lua-users home
lua-l archive

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


you mean:

some C function in your engine pushes a function (that happens to be of C
type) on the LUA stack, lua_pcall() it, and this leaves a full userdata on
the LUA stack as a result, from which you extract the pointer ?
If so, I think your full userdata can be collected anytime you call LUA
again unless you lua_ref() it.
You can even force a gc cycle, and the full userdata will be collected there
and then.
This is because from LUA's point of view, that stack position is not
contained by an active stack frame, therefore gc mark will not find your
full userdata, which will cause its collection.

> -----Original Message-----
> From: lua+Steven.Murdoch@cl.cam.ac.uk
> [mailto:lua+Steven.Murdoch@cl.cam.ac.uk]
> Sent: mardi 10 décembre 2002 16:43
> To: Multiple recipients of list
> Subject: Re: Can full userdata be put back on the stack? 
> 
> 
> > >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.
> 
> Thank you,
> Steven Murdoch.
>