[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Can full userdata be put back on the stack?
- From: lua+Steven.Murdoch@...
- Date: Sat, 07 Dec 2002 01:32:37 +0000
In Lua5.0 say I want a C function that takes full userdata (containing
an int) as a parameter, uses it (but does not modify it) then returns
userdata containing an int of the same value as was passed in. Should
I create new full userdata (with lua_newuserdata(sizeof(int)) and copy
the data over, or is it recommended to push the same userdata as was
passed in on the stack (perhaps with lua_pushlightuserdata)?
The latter option seems more efficient, but it is not clear from the
documentation whether it will work or whether it will have undesirable
effects (such as confusing the garbage collector or the metatable
If I do have to create a new userdata memory location I assume I would
have to copy over the metatable (with lua_getmetatable
lua_setmetatable). Is this correct?
The contents of the userdata can be considered immutable, and will
never be changed after it has been initially set, so there would not
be any aliasing problems from perspective of code written in Lua.