summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorNicolas Noble <pixel@nobis-crew.org>2013-07-30 19:10:20 -0700
committerNicolas Noble <pixel@nobis-crew.org>2013-07-30 19:30:09 -0700
commite7db8576b8a4988dfdd206500199e59c3b57bf55 (patch)
treede40c83fd7eef3d0c443a7e0d9d670b8b6aace64 /includes
parentbabb39375916dc114d3413aa52c9a2c543cad2af (diff)
Changing things a bit in the Lua binding system. Now pushing a class template means pushing a table by its name, and the constructor is implicit in it.
Diffstat (limited to 'includes')
-rw-r--r--includes/BLua.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/includes/BLua.h b/includes/BLua.h
index e11c3fb..a6dd2bc 100644
--- a/includes/BLua.h
+++ b/includes/BLua.h
@@ -223,6 +223,16 @@ struct lua_functypes_t {
true); \
}
+#define DECLARE_CONSTRUCTOR(classname, enumvar) static int constructor(lua_State * L) { \
+ return LuaHelpers<classname>::method_multiplex( \
+ enumvar, \
+ L, \
+ NULL, \
+ sLua_##classname::classname##_proceed_statics, \
+ classname##_functions, \
+ false); \
+ }
+
#define DECLARE_FUNCTION(classname, enumvar) static int function_##enumvar(lua_State * L) { \
return LuaHelpers<classname>::method_multiplex( \
enumvar, \
@@ -233,6 +243,16 @@ struct lua_functypes_t {
false); \
}
+#define DECLARE_STATIC(classname, enumvar) static int static_##enumvar(lua_State * L) { \
+ return LuaHelpers<classname>::method_multiplex( \
+ enumvar, \
+ L, \
+ NULL, \
+ sLua_##classname::classname##_proceed_statics, \
+ classname##_functions, \
+ false); \
+ }
+
#define PUSH_METHOD(classname, enumvar) pushIt( \
L, \
classname##_methods[enumvar].name, \
@@ -243,6 +263,21 @@ struct lua_functypes_t {
String("__") + classname##_methods[enumvar].name, \
sLua_##classname::method_##enumvar)
+#define PUSH_CONSTRUCTOR(classname, enumvar) \
+ bool constructorPushed = true; \
+ L.newtable(); \
+ L.push(#classname); \
+ L.copy(-2); \
+ L.setvar(); \
+ L.declareFunc("new", sLua_##classname::constructor, -1)
+
+#define PUSH_STATIC(classname, enumvar) \
+ AAssert(constructorPushed, "Please call PUSH_CONSTRUCTOR first"); \
+ L.declareFunc( \
+ classname##_functions[enumvar].name, \
+ sLua_##classname::static_##enumvar, \
+ -1)
+
#define PUSH_FUNCTION(classname, enumvar) L.declareFunc( \
classname##_functions[enumvar].name, \
sLua_##classname::function_##enumvar)
@@ -252,6 +287,8 @@ struct lua_functypes_t {
sLua_##classname::function_##enumvar, \
array)
+#define PUSH_CLASS_DONE() L.pop()
+
#define CHECK_METHODS(classname) { \
int i = 0; \
while (classname##_methods[i].number != -1) { \