summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpixel <pixel>2003-12-14 22:04:33 +0000
committerpixel <pixel>2003-12-14 22:04:33 +0000
commit9296144508ae4a98fb43e4b206aa9d83cdf040e3 (patch)
tree1f8bb2fefa3698677808da83174233c2b1d47432
parent187cf873560ca736900db3bb6c8c10d1f75724c4 (diff)
Fixed GC and some related problems.
-rw-r--r--include/BLua.h6
-rw-r--r--lib/BLua.cc30
2 files changed, 24 insertions, 12 deletions
diff --git a/include/BLua.h b/include/BLua.h
index 911b17c..1f746ec 100644
--- a/include/BLua.h
+++ b/include/BLua.h
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: BLua.h,v 1.10 2003-12-14 21:13:32 pixel Exp $ */
+/* $Id: BLua.h,v 1.11 2003-12-14 22:04:33 pixel Exp $ */
#ifndef __BLUA_H__
#define __BLUA_H__
@@ -93,7 +93,7 @@ class LuaObject : public Base {
void pushdestruct(Lua *) throw (GeneralException);
protected:
virtual void pushmembers(Lua *) = 0;
- void pushme(Lua *, void *);
+ void pushme(Lua *, void *, bool = true);
static void pushit(Lua *, const String &, lua_CFunction);
static void pushmeta(Lua *, const String &, lua_CFunction);
bool wantdestruct, pushed;
@@ -196,7 +196,7 @@ class LuaHelpers : public Base {
if (L->istable(i + 1 + add)) {
L->push("__obj");
L->gettable(i + 1 + add);
- invalid = !L->islightuserdata();
+ invalid = !L->isuserdata();
L->pop();
} else {
invalid = !L->isnil(i + 1 + add);
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;
}