lua-users home
lua-l archive

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


I'm sure those that know will correct me if I'm wrong here in any way.

On Tue, Jan 06, 1998 at 01:10:35AM -0200, Steve Dekorte wrote:
> lua_ref() returns a different number each time I call it even if the
> argument is the same object. Is there any way to get a unique identifier for
> a lua object?
> 
> Steve Dekorte

Of course it does. The whole idea of lua_ref() is so that if you store a
"reference" somewhere in your C code, lua will know not to garbage collect
the target. If you store multiple-references, then they have to BE
multiple references and not the same reference.

If you "dereference" the lua_ref, that pointer will be a unique and
directly testable pointer within the system (at least it will be until you
call back into lua and the garbage collector potentially runs). 

So, for example, if you have two lua_refs for the same object, if you
dereference them both, the pointer you get back will be the same.

  get_ref(a_lua_ref) == get_ref(b_lua_ref)


-- 
David Jeske (N9LCA) + http://www.chat.net/~jeske/ + jeske@chat.net