lua-users home
lua-l archive

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


on 7/25/04 12:56 PM, Vincent Penne at ziggy@sashipa.com wrote:

>> * 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.

I think lua_topointer returns a pointer to the current location of some
piece of data associated with the object such as the internal data
structures for a table. This pointer will be unique across Lua universes,
but suffers from the problem that if you cache it in your native data
structures -- e.g., in a global variable -- you need to cache a different
value for each Lua universe.

> 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 ?

The current Lua garbage collector does not move objects but that isn't
promised anywhere and there are plenty of garbage collectors that do move
objects. The Microsoft CLR, for example, I believe uses a copying collector.
A promise in the API that even if a copying collector were added that
lua_topointer would continue to return the same value for any particular
object would potentially make lua_topointer more useful.

Mark