diff options
Diffstat (limited to 'lib/BLua.cc')
-rw-r--r-- | lib/BLua.cc | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/lib/BLua.cc b/lib/BLua.cc index e3e2561..70181be 100644 --- a/lib/BLua.cc +++ b/lib/BLua.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: BLua.cc,v 1.13 2003-12-14 21:13:33 pixel Exp $ */ +/* $Id: BLua.cc,v 1.14 2003-12-14 22:04:33 pixel Exp $ */ #include <lualib.h> @@ -523,11 +523,14 @@ void LuaObject::push(Lua * L) throw (GeneralException) { pushed = true; } -void LuaObject::pushme(Lua * L, void * o) { +void LuaObject::pushme(Lua * L, void * o, bool obj) { void ** u; + bool * b; L->push("__obj"); - u = (void **) L->newuser(sizeof(o)); + u = (void **) L->newuser(sizeof(o) + sizeof(bool)); *u = o; + b = (bool *) (u + 1); + *b = obj; L->settable(-3, true); } @@ -570,24 +573,33 @@ void LuaObject::pushmeta(Lua * L, const String & s, lua_CFunction f) { int LuaStatics::collector(lua_State * _L) { Lua * L = Lua::find(_L); void ** u = (void **) L->touserdata(); - Base * b = (Base *) *u; - delete b; + bool * obj = (bool *) (u + 1); + if (*obj) { + Base * b = (Base *) *u; + delete b; + } else { + free(*u); + } *u = 0; - printm(M_INFO, "Collecting an object from LUA\n"); return 0; } int LuaStatics::destructor(lua_State * _L) { - void ** u; Lua * L = Lua::find(_L); Base * b = (Base *) LuaObject::getme(L); delete b; L->push("__obj"); L->gettable(-2, true); - u = (void **) L->touserdata(); + void ** u = (void **) L->touserdata(); + bool * obj = (bool *) (u + 1); + if (*obj) { + Base * b = (Base *) *u; + delete b; + } else { + free(*u); + } *u = 0; L->pop(); - printm(M_INFO, "Destructing an object from LUA\n"); return 0; } |