[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: tolua, c++, garbagecollection and memory management
- From: "Dirk Ringe" <dirk.ringe@...>
- Date: Thu, 11 Jan 2001 17:09:00 +0100
Hi,
the tolua docs are somewhat cryptic about this, so I just ask the list. We
are currently doing a game with lua as script engine for animation
definitions, user interface and other stuff. We use tolua for binding our
game objects to lua. Now there are some questions about how tolua uses
memory management and works together with the garbage collector. Since we
currently use tolua 3.2, but probably switch to tolua 4.0 when it is ready,
it would be nice if the questions are answered for both versions!
1. I create a c++ object from within lua, with something like
button = CMnuButton:new()
Will the appropriate destructor be called when button leaves the scope
(ie. the GC gets it)?
Ex:
function Dialog()
local b1
local b2
b1 = CMnuButton:new()
b2 = CMnuButton:new()
end
2. Now I register the object within my framework. From now on my framework
should be responsible for this object, and the GC should NOT delete the
userdata associated with button, when button is collected. Is there any
chance to do something like this?
Ex:
function Dialog()
local b1
local b2
b1 = CMnuButton:new()
b2 = CMnuButton:new()
Screen:RegisterButton(b1)
Screen:RegisterButton(b2)
end
3. I have methods that return pointer to an object. Will this object stay
untouched when the var where it is referenced by leaves the scope?
Ex:
function Dialog()
local b1
b1 = Screen:GetActiveButton()
end
4. I see from the code, that tolua makes copies of userdata objects returns
by reference or value. Are these objects correctly collected when they leave
scope?
Thx,
Dirk