aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/ext_ffi_semantics.html16
-rw-r--r--src/lj_cdata.c1
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>
591All of the standard Lua operators can be applied to cdata objects or a 591All of the standard Lua operators can be applied to cdata objects or a
592mix of a cdata object and another Lua object. The following list shows 592mix of a cdata object and another Lua object. The following list shows
593the valid combinations. All other combinations currently raise an 593the pre-defined operations.
594error.
595</p> 594</p>
596<p> 595<p>
597Reference types are dereferenced <em>before</em> performing each of 596Reference types are dereferenced <em>before</em> performing each of
@@ -600,7 +599,8 @@ C&nbsp;type pointed to by the reference.
600</p> 599</p>
601<p> 600<p>
602The pre-defined operations are always tried first before deferring to a 601The pre-defined operations are always tried first before deferring to a
603metamethod for a ctype (if defined). 602metamethod or index table (if any) for the corresponding ctype. An error
603is 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
625object</a>. A write access <a href="#convert_fromlua">converts a Lua 625object</a>. A write access <a href="#convert_fromlua">converts a Lua
626object to the field type</a> and stores the converted value to the 626object to the field type</a> and stores the converted value to the
627field. An error is raised if a write access to a constant 627field. 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.
629Scoped enum constants or static constants are treated like a constant
630field.</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
631either by a cdata number or a Lua number with the values 0 or 1, or by 633either 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>
649A ctype object can be indexed with a string key, too. The only
650pre-defined operation is reading scoped constants of
651<tt>struct</tt>/<tt>union</tt> types. All other accesses defer
652to the corresponding metamethods or index tables (if any).
653</p>
654<p>
647Note: since there's (deliberately) no address-of operator, a cdata 655Note: since there's (deliberately) no address-of operator, a cdata
648object holding a value type is effectively immutable after 656object holding a value type is effectively immutable after
649initialization. The JIT compiler benefits from this fact when applying 657initialization. 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 '->'. */