summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/BLua.cc32
-rw-r--r--lib/LuaHandle.cc14
2 files changed, 27 insertions, 19 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;
diff --git a/lib/LuaHandle.cc b/lib/LuaHandle.cc
index 487470d..373066f 100644
--- a/lib/LuaHandle.cc
+++ b/lib/LuaHandle.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: LuaHandle.cc,v 1.6 2003-12-06 04:26:17 pixel Exp $ */
+/* $Id: LuaHandle.cc,v 1.7 2003-12-07 04:44:38 pixel Exp $ */
#include "LuaHandle.h"
@@ -601,16 +601,8 @@ void LuaOutput::pushmembers(Lua * L) {
void LuaBuffer::pushmembers(Lua * L) {
LuaHandle::pushmembers(L);
- if (!L->getmetatable(1)) {
- L->newtable();
- }
- L->push("__index");
- L->push(sLuaHandle::bindex);
- L->settable();
- L->push("__newindex");
- L->push(sLuaHandle::bnewindex);
- L->settable();
- L->setmetatable(1);
+ pushmeta(L, "__index", sLuaHandle::bindex);
+ pushmeta(L, "__newindex", sLuaHandle::bnewindex);
pushit(L, "wtell", sLuaHandle::btell);
pushit(L, "wseek", sLuaHandle::bseek);
}