summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas "Pixel" Noble <pixel@nobis-crew.org>2013-07-31 09:54:35 +0200
committerNicolas "Pixel" Noble <pixel@nobis-crew.org>2013-07-31 09:54:35 +0200
commited4e627d314bff09013dbd5547b2dcb40eb43037 (patch)
treef81fa51059928b7456775b83882de52a892bf022
parentc39b1a665114ad2a8231f0ea69f9c730cc434070 (diff)
Few more tweaks to the Lua class exporter. Now we have parent support as well as as the class name.
-rw-r--r--includes/BLua.h24
-rw-r--r--tests/test-Lua.cc1
2 files changed, 18 insertions, 7 deletions
diff --git a/includes/BLua.h b/includes/BLua.h
index 926782a..6db642e 100644
--- a/includes/BLua.h
+++ b/includes/BLua.h
@@ -264,26 +264,36 @@ struct lua_functypes_t {
sLua_##classname::method_##enumvar)
#define PUSH_CLASS(classname) \
- bool constructorPushed = false; \
+ bool classPushed = true; \
{ \
L.newtable(); \
+ L.push("name"); \
L.push(#classname); \
- L.copy(-2); \
+ L.copy(); \
+ L.copy(-4); \
L.setvar(); \
+ L.settable(); \
}
-#define PUSH_CONSTRUCTOR(classname, enumvar) \
- bool constructorPushed = true; \
+#define PUSH_SUBCLASS(classname, parentname) \
+ bool classPushed = true; \
{ \
L.newtable(); \
+ L.push("name"); \
L.push(#classname); \
- L.copy(-2); \
+ L.copy(); \
+ L.copy(-4); \
L.setvar(); \
- L.declareFunc("new", sLua_##classname::constructor, -1); \
+ L.settable(); \
+ L.push("parent"); \
+ L.getglobal(#parentname); \
+ L.settable(); \
}
+#define PUSH_CONSTRUCTOR(classname, enumvar) L.declareFunc("new", sLua_##classname::constructor, -1)
+
#define PUSH_STATIC(classname, enumvar) { \
- AAssert(constructorPushed, "Please call PUSH_CONSTRUCTOR first"); \
+ AAssert(classPushed, "Please call PUSH_(SUB)CLASS first"); \
L.declareFunc( \
classname##_functions[enumvar].name, \
sLua_##classname::static_##enumvar, \
diff --git a/tests/test-Lua.cc b/tests/test-Lua.cc
index 1925033..fec6f11 100644
--- a/tests/test-Lua.cc
+++ b/tests/test-Lua.cc
@@ -65,6 +65,7 @@ class LuaObjectTestFactory : public LuaObjectFactory {
CHECK_METHODS(ObjectTest);
CHECK_FUNCTIONS(ObjectTest);
+ PUSH_CLASS(ObjectTest);
PUSH_CONSTRUCTOR(ObjectTest, OBJECTTEST_CONSTRUCTOR);
PUSH_STATIC(ObjectTest, OBJECTTEST_SOMESTATIC);
PUSH_FUNCTION(ObjectTest, OBJECTTEST_SOMEFUNCTION);