summaryrefslogtreecommitdiff
path: root/src/BLua.cc
diff options
context:
space:
mode:
authorNicolas Noble <pixel@nobis-crew.org>2013-07-31 11:31:38 -0700
committerNicolas Noble <pixel@nobis-crew.org>2013-07-31 11:31:38 -0700
commit5ce610659adea3159549d4863c2479163fce89f4 (patch)
treee89d1084386d551bd42def29a5a3507c7e3f0c2c /src/BLua.cc
parented4e627d314bff09013dbd5547b2dcb40eb43037 (diff)
Even further changes in the Lua class binding system. Simplifying the callback system by using the Lua's C closure mechanism.
Diffstat (limited to 'src/BLua.cc')
-rw-r--r--src/BLua.cc26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/BLua.cc b/src/BLua.cc
index 48a3305..5bbdd07 100644
--- a/src/BLua.cc
+++ b/src/BLua.cc
@@ -804,7 +804,7 @@ void Balau::LuaObjectFactory::pushMe(Lua & L, LuaObjectBase * o, const char * ob
L.push(objname);
L.settable(-3, true);
}
- pushIt(L, "destroy", LuaStatics::destructor);
+ pushMethod(L, "destroy", LuaStatics::destructor);
if (!m_wantsDestruct)
o->detach();
}
@@ -827,17 +827,29 @@ Balau::LuaObjectBase * Balau::LuaObjectFactory::getMeInternal(Lua & L, int i) {
return o;
}
-void Balau::LuaObjectFactory::pushIt(Lua & L, const char * s, lua_CFunction f) {
- L.push(s);
- L.push(f);
+void Balau::LuaObjectFactory::pushMethod(Lua & L, const char * s, int strSize, lua_CFunction f, int upvalues) {
+ if (upvalues == 0) {
+ L.push(s, strSize);
+ L.push(f);
+ } else {
+ L.push(f, upvalues);
+ L.push(s, strSize);
+ L.insert(-2);
+ }
L.settable(-3, true);
}
-void Balau::LuaObjectFactory::pushMeta(Lua & L, const char * s, lua_CFunction f) {
+void Balau::LuaObjectFactory::pushMeta(Lua & L, const char * s, int strSize, lua_CFunction f, int upvalues) {
if (!L.getmetatable())
L.newtable();
- L.push(s);
- L.push(f);
+ if (upvalues == 0) {
+ L.push(s);
+ L.push(f);
+ } else {
+ L.push(f, upvalues);
+ L.push(s, strSize);
+ L.insert(-2);
+ }
L.settable();
L.setmetatable();
}