lua-users home
lua-l archive

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


Mark Hamburg wrote:

The Lua 5 approach is somewhat less efficient than one might like. If
efficiency is a concern, there are a variety of things one can do:

* Rather than using strings to identify types, use light userdata. This
assumes that you have some permanent address to use for this purpose. This
will avoid some string manipulation when doing type-testing.

Indeed. I was thinking about using a number (similar to lua 4 tag), with the difference that it would now be a float, but a light userdata would be even better here. However, it still involves the lookup into the registry when converting the metatable to this ID.

* If one counts on the garbage collector not moving things or at least on
lua_topointer being stable, you could use do a comparison on the result of
lua_topointer with the metatable. Note that this only works if your program
limits itself to creating only one Lua universe.

Does lua_topointer return a pointer on the internal lua structure of the lua object ? (the metatable in this case) If so, that would work perfectly. It does not even limit you to one lua state, if your C code store these metatable adresses in different structures for each lua state.

However, you talk about the garbage collector. Is it possible that a lua object that is never garbage collected get moved in memory ? Is it a new feature of lua 5 ?