lua-users home
lua-l archive

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


Mike Pall wrote:
>
> I think the fastest solution is to register all methods with an upvalue
> that holds a reference to the metatable. Storing and retrieving the
> metatable to/from the registry is not necessary. And you don't have to
> provide a unique name or a unique memory address for all of your userdata
> types.

That's what I'm using.  It works well.  But, as Vincent mentioned, it
becomes really ugly once you put a lot of stuff into upvalues (incl.
string constants etc).  Managing which function needs which upvalues
becomes tricky and the memory overhead grows a lot because these values
are copied for each closure.

My suggestion: a (module) private registry as I outlined some weeks
ago and a new special index 'lua_registryindex(i)' which addresses
numeric indexes in that private registry.

That way one could put all that module-global stuff (like meta tables,
string constants, mappings, etc) once into the registry and access
them everywhere within the module via numerical constants.
Speed would be nearly as fast as upvalues.

> Adding the following to lapi.c would allow for an even faster solution:
> 
> void *lua_touserdata_mc(lua_State *L, int indexu, int indexm)

Yeah ;-)

Ciao, ET.