summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);