[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Fast metamethods for Userdata types
- From: Javier Guerra Giraldez <javier@...>
- Date: Tue, 7 Apr 2015 16:01:26 -0500
On Tue, Apr 7, 2015 at 3:50 PM, Dibyendu Majumdar
<mobile@majumdar.org.uk> wrote:
> Now if you think of
> Ravi where the [] operator on an array is specialized - and executed
> inline for gets, then the cost of a hash table lookup and then going
> through the mechanism for a function call is enormous.
In LuaJIT, methametods are added to ffi objects using the
`ffi.metatype(ct, metatable)`, where `ct` is the ffi type and
`metatable` is compatible with the plain Lua metatable. But the user
is not allowed to modify the metatable, its contents, or it's __index
contents after the call to metatype().
I guess that allows LuaJIT to statically set all the function
bindings, and the result is that adding simple methods to ffi objects
is _very_ efficient, and typically gets fully compiled.
--
Javier