[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Can full userdata be put back on the stack?
- From: lua+Steven.Murdoch@...
- Date: Tue, 10 Dec 2002 15:42:39 +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)?
> It depends on whether you want the same value returned or a different value.
> If it's the same value, you can use lua_pushvalue to put it on the stack to
> be returned.
I think I oversimplified the question. Say the C program gets a full userdata
from a call to a C function from Lua. Can the C program keep the pointer to
the memory location and push this onto the stack when a different C function
is called by Lua. A reference to the userdata will be maintained by Lua so it
will not be garbage collected.