lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Stefan Behnel wrote:
> From looking at the function in LuaJIT2 (2.0.0-beta5), it basically
> only calls internal functions, so it's not clear to me what I can do
> to avoid the call.

Yes, I've optimized this one as much as possible. The real issue
is that the design of the luaL_*udata API functions is suboptimal.
But you don't need to use these at all.

You can either follow Luiz suggestions or here are some more:
- Create all userdata methods with the C function environment
  holding a reference to the userdata metatable. Then you can
  just use lua_getmetatable() + lua_rawequal().
- Or use a C function upvalue, if the environment table is already
  used for something else.

[Actually the internal userdata methods in LuaJIT have a much
faster check, using a 16 bit udtype field in every userdata. See
io_tofilep() in lib_io.c. Alas, this mechanism is not available
for external methods and it might change anytime.]

--Mike