mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-07 15:14:08 +00:00
FFI: Resolve metamethods for constructors, too.
This commit is contained in:
parent
126f9906fe
commit
6cee1333ef
@ -590,8 +590,7 @@ ffi.new("struct nested", {x=1,y={2,3}}) --> x = 1, y.a = 2, y.b = 3
|
|||||||
<p>
|
<p>
|
||||||
All of the standard Lua operators can be applied to cdata objects or a
|
All of the standard Lua operators can be applied to cdata objects or a
|
||||||
mix of a cdata object and another Lua object. The following list shows
|
mix of a cdata object and another Lua object. The following list shows
|
||||||
the valid combinations. All other combinations currently raise an
|
the pre-defined operations.
|
||||||
error.
|
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Reference types are dereferenced <em>before</em> performing each of
|
Reference types are dereferenced <em>before</em> performing each of
|
||||||
@ -600,7 +599,8 @@ C type pointed to by the reference.
|
|||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
The pre-defined operations are always tried first before deferring to a
|
The pre-defined operations are always tried first before deferring to a
|
||||||
metamethod for a ctype (if defined).
|
metamethod or index table (if any) for the corresponding ctype. An error
|
||||||
|
is raised if the metamethod lookup or index table lookup fails.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h3 id="cdata_array">Indexing a cdata object</h3>
|
<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
|
|||||||
object</a>. A write access <a href="#convert_fromlua">converts a Lua
|
object</a>. A write access <a href="#convert_fromlua">converts a Lua
|
||||||
object to the field type</a> and stores the converted value to the
|
object to the field type</a> and stores the converted value to the
|
||||||
field. An error is raised if a write access to a constant
|
field. An error is raised if a write access to a constant
|
||||||
<tt>struct</tt>/<tt>union</tt> or a constant field is attempted.</li>
|
<tt>struct</tt>/<tt>union</tt> or a constant field is attempted.
|
||||||
|
Scoped enum constants or static constants are treated like a constant
|
||||||
|
field.</li>
|
||||||
|
|
||||||
<li><b>Indexing a complex number</b>: a complex number can be indexed
|
<li><b>Indexing a complex number</b>: a complex number can be indexed
|
||||||
either by a cdata number or a Lua number with the values 0 or 1, or by
|
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>
|
|||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
<p>
|
<p>
|
||||||
|
A ctype object can be indexed with a string key, too. The only
|
||||||
|
pre-defined operation is reading scoped constants of
|
||||||
|
<tt>struct</tt>/<tt>union</tt> types. All other accesses defer
|
||||||
|
to the corresponding metamethods or index tables (if any).
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
Note: since there's (deliberately) no address-of operator, a cdata
|
Note: since there's (deliberately) no address-of operator, a cdata
|
||||||
object holding a value type is effectively immutable after
|
object holding a value type is effectively immutable after
|
||||||
initialization. The JIT compiler benefits from this fact when applying
|
initialization. The JIT compiler benefits from this fact when applying
|
||||||
|
@ -178,6 +178,7 @@ collect_attrib:
|
|||||||
if (fct && ctype_isconstval(fct->info))
|
if (fct && ctype_isconstval(fct->info))
|
||||||
return fct;
|
return fct;
|
||||||
}
|
}
|
||||||
|
ct = sct; /* Allow resolving metamethods for constructors, too. */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ctype_isptr(ct->info)) { /* Automatically perform '->'. */
|
if (ctype_isptr(ct->info)) { /* Automatically perform '->'. */
|
||||||
|
Loading…
Reference in New Issue
Block a user