lua-users home
lua-l archive

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

> The way I have been doing this, is by keeping the object in a 
> table "allObject={}" so that I can find the object by using 
> the pointer of the C++ object as key, and getting the correct 
> table back as value, at which point I can then call the 

This is the standard way of doing it.  You could use the lua_ref() set
of macros, but they're doing essentially the same thing.

> predefined function, but this lookup is slow, and storing the 
> object in my 'database' and a lua table shouldnt be necessary. 

The lookup is actually pretty fast, and at least in my app never shows
up on a profile.

> I'v tried using lua_gettop() to find the index of the object 
> and then using that index to 'recall' the object to the top 
> of the stack, but that doesnt work.

The index returned by lua_gettop() is transient, so that won't work.
IOW, as the stack grows and shrinks, new items will reuse stack indices,
and old items will be GC'd.

The first method you mentioned is probably the way to go.