Re: Questions about luabind::object
Iliya Trendafilov <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
luabind::object keeps objects in the Lua registry: http://www.lua.org/manual/5.1/manual.html#3.5 So you can safely pop your object from the stack and it won't be garbage collected. The lifetime of the object is indeed controlled by TheChunk - luabind::object will remove the value it holds in its destructor (before you ask, copying luabind::objects is ok and storing different luabind::object instances holding the same Lua object works as expected - the Lua object is removed from the registry and therefore left vulnerable for garbage collecting only when the last instance of luabind::object is destroyed) As for your first question, I believe construction of luabind::object doesn't have any reasons to modify the stack. And it's easy to verify that in practice. On Thu, Dec 3, 2009 at 9:14 AM, Jason McKesson <[email protected]> wrote: > I have a question about the interaction with the stack for > luabind::object instances and lifetimes. > > OK, so I have a lua chunk. I have loaded it with lua_load. Therefore, it > is on the stack at index -1. So if I do: > > luabind::object TheChunk(luabind::from_stack(pState, -1)) > > The variable "TheChunk" will hold this function. > > So question 1: Is the function still on the stack? It looks like it is > from the documentation, as it says that "This will create the object o > and copy the value from the top of the lua stack." > > Question 2: If it is still on the stack, what happens to the object if I > pop it off of the stack? Is the object in danger of being garbage > collected after popping it, or is the object lifetime now controlled by > the lifetime of "TheChunk"? > > Question 3: If the object holds a copy, exactly where is this copy? If > the copy is considered a valid Lua reference (thus making it ineligible > for garbage collection), how exactly does that work? How does Luabind > accomplish this? > > ------------------------------------------------------------------------------ > Join us December 9, 2009 for the Red Hat Virtual Experience, > a free event focused on virtualization and cloud computing. > Attend in-depth sessions from your desk. Your couch. Anywhere. > http://p.sf.net/sfu/redhat-sfdev2dev > _______________________________________________ > luabind-user mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/luabind-user > ------------------------------------------------------------------------------ Join us December 9, 2009 for the Red Hat Virtual Experience, a free event focused on virtualization and cloud computing. Attend in-depth sessions from your desk. Your couch. Anywhere. http://p.sf.net/sfu/redhat-sfdev2dev