lua-users home
lua-l archive

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


I was wondering... once a heavy user data is created with
lua_newuserdata(), is it guaranteed to stay at that same returned
address until it is finally destroyed?  For all I know,
the GC system moves objects around to help stop lua's
heap fragmenting, if not now then in a future version of the
garbage collector, but I don't want my heavy userdata moved.

I'm using tables of heavy-to-light userdata mappings to help
various parts of my project to pass (finalizable) hunks up through
a C API and back again; the 'light' userdata is just the raw
pointer that lua_newuserdata() returns, then these both get
put into the tables so I can map from one to the other (lua
uses the heavy versions but they need to be passed through the
C API and back again in their 'light' forms).  But if heavy
userdata can move at some point so that lua_touserdata() differs
between the heavy and the light versions, I lose.

On a related point, if heavy userdata cannot move then it would be
VERY handy if heavy and light userdata hashed the same way from
within lua.  Since AFAIK there's no way to distinguish between the
two types anyway from within lua (even typeof() prints exactly the
same) I think it's a fairly reasonable thing to ask or expect (and
the lack of this behaviour and its difficult debuggability caused
me a lot of confusion in the past).

Adam D. Moss   . ,,^^   co:3