summaryrefslogtreecommitdiff
path: root/lib/BLua.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/BLua.cc')
-rw-r--r--lib/BLua.cc32
1 files changed, 24 insertions, 8 deletions
diff --git a/lib/BLua.cc b/lib/BLua.cc
index 7a4f1d9..9e5373e 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.7 2003-12-04 04:09:02 pixel Exp $ */
+/* $Id: BLua.cc,v 1.8 2003-12-07 04:44:38 pixel Exp $ */
#include <lualib.h>
@@ -224,6 +224,14 @@ void Lua::push(bool b) {
lua_pushboolean(L, b);
}
+void Lua::push(char * s, int size) {
+ if (size < 0) {
+ lua_pushstring(L, s);
+ } else {
+ lua_pushlstring(L, s, size);
+ }
+}
+
void Lua::push(void * p) {
lua_pushlightuserdata(L, p);
}
@@ -256,6 +264,10 @@ void Lua::gettable(int i, bool raw) {
}
}
+void Lua::setvar() {
+ lua_settable(L, LUA_GLOBALSINDEX);
+}
+
int Lua::gettop() {
return lua_gettop(L);
}
@@ -486,6 +498,16 @@ void LuaObject::pushit(Lua * L, const String & s, lua_CFunction f) {
L->settable();
}
+void LuaObject::pushmeta(Lua * L, const String & s, lua_CFunction f) {
+ if (!L->getmetatable(1)) {
+ L->newtable();
+ }
+ L->push(s);
+ L->push(f);
+ L->settable();
+ L->setmetatable(1);
+}
+
int LuaStatics::destructor(lua_State * _L) {
Lua * L = Lua::find(_L);
Base * b = (Base *) LuaObject::getme(L);
@@ -502,13 +524,7 @@ void LuaObject::pushdestruct(Lua * L) throw (GeneralException) {
throw GeneralException("Error: can't push destructor, object already pushed");
}
push(L);
- if (!L->getmetatable(1)) {
- L->newtable();
- }
- L->push("__gc");
- L->push(LuaStatics::destructor);
- L->settable();
- L->setmetatable(1);
+ pushmeta(L, "__gc", LuaStatics::destructor);
pushit(L, "destroy", LuaStatics::destructor);
wantdestruct = true;