lua-users home
lua-l archive

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

on 2/28/08 4:43 PM, Diego Nehab at wrote:

> Hi,
> Sure. I don't have the code on me right now. The main
> ideas is this:
>      Avoid the strings as class names. Use lightuserdata
>      instead. The key contains the addresses of the strings, not
>      the values of the strings. The strings are extern const
>      strings defined in whatever module created the class, and
>      exported in its .h file.
> So to set a userdata to a class, you only need one rawget,
> using a lightuserdata as key, from the class table (which
> can be the registry or a private table in an upvalue), plus
> one setmetatable.
> To check a userdata you need one touserdata, that one rawget,
> one getmetatable, and one isequal.
> The savings come from the fact you don't traverse strings,
> ever, and you don't create strings, ever.

Which leads to a Lua API request for 5.2:

    lua_rawgetud (lua_State* L, const void* ud);
    lua_rawsetud (lua_State* L, const void* ud);

Get and set a table indexed via a userdata.