Hi,
Michael Bauroth wrote:
Hi,
I've made a Lua based GUI application with Lunar binding to the C++
core. The GUI will be constructed in Lua, backed by related C++
classes. Sometimes I build temporary hierarchical structures (e.g.
panel with 3 buttons), which I want to delete later on.
Now my question: Is it possible to simply call the explicit destructor
of such a base node from Lua side (Lunar approach), so that the C++
core can remove the hierarchy or is the only way to set the Lua
variable to nil, so that the garbage collection can make the rest?
Unfortunately haven't found something meaningful in the net until now.
General answer to similar questions (closing file, releasing resource,
etc.) was/is:
- Supply a destroy/delete function to Lua side
- When called, delete C++ side objects, and record that situation (ie.
ptr=0)
- Let garbage collector do its job whenever it like
For example:
class A {};
class LunarA {
A* self_;
public:
LunarA() { self_ = new A; }
~LunarA() { delete self_; }
void destroy(lua_State* L) { delete self_; self_ = 0; }
};
Best Regards
Micha
--
Regards,
Hakki Dogusan