diff options
| author | Mike Pall <mike> | 2012-06-20 15:15:09 +0200 |
|---|---|---|
| committer | Mike Pall <mike> | 2012-06-20 15:16:40 +0200 |
| commit | 6cee1333ef2b340e1b23e3051b9f433fc803d2ff (patch) | |
| tree | 43052260288c8208d2b049852242aaa2ad0f1e0c | |
| parent | 126f9906febcc90243a34191ab8986b9487cf186 (diff) | |
| download | luajit-6cee1333ef2b340e1b23e3051b9f433fc803d2ff.tar.gz luajit-6cee1333ef2b340e1b23e3051b9f433fc803d2ff.tar.bz2 luajit-6cee1333ef2b340e1b23e3051b9f433fc803d2ff.zip | |
FFI: Resolve metamethods for constructors, too.
| -rw-r--r-- | doc/ext_ffi_semantics.html | 16 | ||||
| -rw-r--r-- | src/lj_cdata.c | 1 |
2 files changed, 13 insertions, 4 deletions
diff --git a/doc/ext_ffi_semantics.html b/doc/ext_ffi_semantics.html index bacb4fb8..4b498fbe 100644 --- a/doc/ext_ffi_semantics.html +++ b/doc/ext_ffi_semantics.html | |||
| @@ -590,8 +590,7 @@ ffi.new("struct nested", {x=1,y={2,3}}) --> x = 1, y.a = 2, y.b = 3 | |||
| 590 | <p> | 590 | <p> |
| 591 | All of the standard Lua operators can be applied to cdata objects or a | 591 | All of the standard Lua operators can be applied to cdata objects or a |
| 592 | mix of a cdata object and another Lua object. The following list shows | 592 | mix of a cdata object and another Lua object. The following list shows |
| 593 | the valid combinations. All other combinations currently raise an | 593 | the pre-defined operations. |
| 594 | error. | ||
| 595 | </p> | 594 | </p> |
| 596 | <p> | 595 | <p> |
| 597 | Reference types are dereferenced <em>before</em> performing each of | 596 | Reference types are dereferenced <em>before</em> performing each of |
| @@ -600,7 +599,8 @@ C type pointed to by the reference. | |||
| 600 | </p> | 599 | </p> |
| 601 | <p> | 600 | <p> |
| 602 | The pre-defined operations are always tried first before deferring to a | 601 | The pre-defined operations are always tried first before deferring to a |
| 603 | metamethod for a ctype (if defined). | 602 | metamethod or index table (if any) for the corresponding ctype. An error |
| 603 | is raised if the metamethod lookup or index table lookup fails. | ||
| 604 | </p> | 604 | </p> |
| 605 | 605 | ||
| 606 | <h3 id="cdata_array">Indexing a cdata object</h3> | 606 | <h3 id="cdata_array">Indexing a cdata object</h3> |
| @@ -625,7 +625,9 @@ field value and <a href="#convert_tolua">converts it to a Lua | |||
| 625 | object</a>. A write access <a href="#convert_fromlua">converts a Lua | 625 | object</a>. A write access <a href="#convert_fromlua">converts a Lua |
| 626 | object to the field type</a> and stores the converted value to the | 626 | object to the field type</a> and stores the converted value to the |
| 627 | field. An error is raised if a write access to a constant | 627 | field. An error is raised if a write access to a constant |
| 628 | <tt>struct</tt>/<tt>union</tt> or a constant field is attempted.</li> | 628 | <tt>struct</tt>/<tt>union</tt> or a constant field is attempted. |
| 629 | Scoped enum constants or static constants are treated like a constant | ||
| 630 | field.</li> | ||
| 629 | 631 | ||
| 630 | <li><b>Indexing a complex number</b>: a complex number can be indexed | 632 | <li><b>Indexing a complex number</b>: a complex number can be indexed |
| 631 | either by a cdata number or a Lua number with the values 0 or 1, or by | 633 | either by a cdata number or a Lua number with the values 0 or 1, or by |
| @@ -644,6 +646,12 @@ assigning to an index of a vector raises an error.</li> | |||
| 644 | 646 | ||
| 645 | </ul> | 647 | </ul> |
| 646 | <p> | 648 | <p> |
| 649 | A ctype object can be indexed with a string key, too. The only | ||
| 650 | pre-defined operation is reading scoped constants of | ||
| 651 | <tt>struct</tt>/<tt>union</tt> types. All other accesses defer | ||
| 652 | to the corresponding metamethods or index tables (if any). | ||
| 653 | </p> | ||
| 654 | <p> | ||
| 647 | Note: since there's (deliberately) no address-of operator, a cdata | 655 | Note: since there's (deliberately) no address-of operator, a cdata |
| 648 | object holding a value type is effectively immutable after | 656 | object holding a value type is effectively immutable after |
| 649 | initialization. The JIT compiler benefits from this fact when applying | 657 | initialization. The JIT compiler benefits from this fact when applying |
diff --git a/src/lj_cdata.c b/src/lj_cdata.c index 482add4b..b477ce77 100644 --- a/src/lj_cdata.c +++ b/src/lj_cdata.c | |||
| @@ -178,6 +178,7 @@ collect_attrib: | |||
| 178 | if (fct && ctype_isconstval(fct->info)) | 178 | if (fct && ctype_isconstval(fct->info)) |
| 179 | return fct; | 179 | return fct; |
| 180 | } | 180 | } |
| 181 | ct = sct; /* Allow resolving metamethods for constructors, too. */ | ||
| 181 | } | 182 | } |
| 182 | } | 183 | } |
| 183 | if (ctype_isptr(ct->info)) { /* Automatically perform '->'. */ | 184 | if (ctype_isptr(ct->info)) { /* Automatically perform '->'. */ |
