summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-06-15 23:31:06 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-06-15 23:31:06 +0200
commit7d4abe001eb004755b361932875256ce83252b71 (patch)
treefc825f9c74cfcb2401ce61919e12ed4c38faed4b /source
parentLit furnaces can be used by players (diff)
downloadcuberite-7d4abe001eb004755b361932875256ce83252b71.tar
cuberite-7d4abe001eb004755b361932875256ce83252b71.tar.gz
cuberite-7d4abe001eb004755b361932875256ce83252b71.tar.bz2
cuberite-7d4abe001eb004755b361932875256ce83252b71.tar.lz
cuberite-7d4abe001eb004755b361932875256ce83252b71.tar.xz
cuberite-7d4abe001eb004755b361932875256ce83252b71.tar.zst
cuberite-7d4abe001eb004755b361932875256ce83252b71.zip
Diffstat (limited to 'source')
-rw-r--r--source/Bindings.cpp2
-rw-r--r--source/Bindings.h2
-rw-r--r--source/LuaItems.h2
-rw-r--r--source/ManualBindings.cpp252
4 files changed, 90 insertions, 168 deletions
diff --git a/source/Bindings.cpp b/source/Bindings.cpp
index 2edcd2c23..2c3af87bb 100644
--- a/source/Bindings.cpp
+++ b/source/Bindings.cpp
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 06/14/12 21:17:55.
+** Generated automatically by tolua++-1.0.92 on 06/15/12 23:23:53.
*/
#ifndef __cplusplus
diff --git a/source/Bindings.h b/source/Bindings.h
index b64b6f5c4..3a224fd25 100644
--- a/source/Bindings.h
+++ b/source/Bindings.h
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 06/14/12 21:17:55.
+** Generated automatically by tolua++-1.0.92 on 06/15/12 23:23:53.
*/
/* Exported function */
diff --git a/source/LuaItems.h b/source/LuaItems.h
index deec7f205..37bd713c4 100644
--- a/source/LuaItems.h
+++ b/source/LuaItems.h
@@ -43,6 +43,7 @@ public:
{
m_Items[a_Idx] = cItem(a_ItemType, a_ItemCount, a_ItemHealth);
}
+
protected:
cItems & m_Items;
} ;
@@ -50,3 +51,4 @@ protected:
+
diff --git a/source/ManualBindings.cpp b/source/ManualBindings.cpp
index 8349f52f0..383f792b2 100644
--- a/source/ManualBindings.cpp
+++ b/source/ManualBindings.cpp
@@ -102,177 +102,97 @@ static int tolua_LOGERROR(lua_State* tolua_S)
-static int tolua_cRoot_ForEachWorld(lua_State * tolua_S)
-{
- int NumArgs = lua_gettop( tolua_S ) - 1; // This includes 'self'
- if ((NumArgs != 1) && (NumArgs != 2))
- {
- LOGWARN("Error in function call 'ForEachWorld': Requires 1 or 2 arguments, got %i", NumArgs);
- return 0;
- }
-
- cRoot * self = (cRoot *)tolua_tousertype(tolua_S, 1, 0);
-
- if (!lua_isfunction(tolua_S, 2))
- {
- LOGWARN("Error in function call 'ForEachWorld': Expected a function for parameter #1");
- return 0;
- }
-
- // luaL_ref gets reference to value on top of the stack, the table is the last argument and therefore on the top
- int TableRef = LUA_REFNIL;
- if( NumArgs == 2 )
- {
- TableRef = luaL_ref(tolua_S, LUA_REGISTRYINDEX);
- if( TableRef == LUA_REFNIL )
- {
- LOGWARN("Error in function call 'ForEachWorld': Could not get value reference of parameter #2");
- return 0;
- }
- }
-
- // table value is popped, and now function is on top of the stack
- int FuncRef = luaL_ref(tolua_S, LUA_REGISTRYINDEX);
- if( FuncRef == LUA_REFNIL )
- {
- LOGWARN("Error in function call 'ForEachWorld': Could not get function reference of parameter #1");
- return 0;
- }
-
- class cLuaWorldCallback : public cWorldListCallback
- {
- public:
- cLuaWorldCallback( lua_State* a_LuaState, int a_FuncRef, int a_TableRef )
- : LuaState( a_LuaState )
- , FuncRef( a_FuncRef )
- , TableRef( a_TableRef )
- {}
-
- private:
- virtual bool Item(cWorld * a_World) override
- {
- lua_rawgeti( LuaState, LUA_REGISTRYINDEX, FuncRef); // Push function reference
- tolua_pushusertype( LuaState, a_World, "cWorld" );
- if (TableRef != LUA_REFNIL)
- {
- lua_rawgeti(LuaState, LUA_REGISTRYINDEX, TableRef); // Push table reference
- }
-
- int s = lua_pcall( LuaState, (TableRef == LUA_REFNIL ? 1 : 2), 1, 0);
- if (report_errors(LuaState, s))
- {
- return true; // break enumeration
- }
-
- if (lua_isboolean( LuaState, -1))
- {
- return (tolua_toboolean( LuaState, -1, 0) > 0);
- }
- return false; // continue enumeration
- }
- lua_State* LuaState;
- int FuncRef;
- int TableRef;
- } Callback( tolua_S, FuncRef, TableRef );
-
- bool bRetVal = self->ForEachWorld(Callback);
-
- // Unreference the values again, so the LUA_REGISTRYINDEX can make place for other references
- luaL_unref( tolua_S, LUA_REGISTRYINDEX, TableRef );
- luaL_unref( tolua_S, LUA_REGISTRYINDEX, FuncRef );
-
- // Push return value on stack
- tolua_pushboolean( tolua_S, bRetVal );
- return 1;
+#define DEFINE_LUA_FOREACH(CONTAINER,ITEM,FOREACH,FNNAME) \
+static int FNNAME(lua_State * tolua_S) \
+{ \
+ int NumArgs = lua_gettop(tolua_S) - 1; /* This includes 'self' */ \
+ if( NumArgs != 1 && NumArgs != 2) \
+ { \
+ LOGWARN("Error in function call '" #FOREACH "': Requires 1 or 2 arguments, got %i", NumArgs ); \
+ return 0; \
+ } \
+ \
+ CONTAINER * self = (CONTAINER *) tolua_tousertype(tolua_S, 1, 0); \
+ \
+ if (!lua_isfunction( tolua_S, 2)) \
+ { \
+ LOGWARN("Error in function call '" #FOREACH "': Expected a function for parameter #1"); \
+ return 0; \
+ } \
+ \
+ /* luaL_ref gets reference to value on top of the stack, the table is the last argument and therefore on the top */ \
+ int TableRef = LUA_REFNIL; \
+ if (NumArgs == 2) \
+ { \
+ TableRef = luaL_ref(tolua_S, LUA_REGISTRYINDEX); \
+ if (TableRef == LUA_REFNIL) \
+ { \
+ LOGWARN("Error in function call '" #FOREACH "': Could not get value reference of parameter #2"); \
+ return 0; \
+ } \
+ } \
+ \
+ /* table value is popped, and now function is on top of the stack */ \
+ int FuncRef = luaL_ref(tolua_S, LUA_REGISTRYINDEX); \
+ if (FuncRef == LUA_REFNIL) \
+ { \
+ LOGWARN("Error in function call '" #FOREACH "': Could not get function reference of parameter #1"); \
+ return 0; \
+ } \
+ \
+ class cLuaPlayerCallback : public cItemCallback<ITEM> \
+ { \
+ public: \
+ cLuaPlayerCallback(lua_State* a_LuaState, int a_FuncRef, int a_TableRef) \
+ : LuaState( a_LuaState ) \
+ , FuncRef( a_FuncRef ) \
+ , TableRef( a_TableRef ) \
+ {} \
+ \
+ private: \
+ virtual bool Item(ITEM * a_Item) override \
+ { \
+ lua_rawgeti( LuaState, LUA_REGISTRYINDEX, FuncRef); /* Push function reference */ \
+ tolua_pushusertype( LuaState, a_Item, #ITEM ); \
+ if (TableRef != LUA_REFNIL) \
+ { \
+ lua_rawgeti( LuaState, LUA_REGISTRYINDEX, TableRef); /* Push table reference */ \
+ } \
+ \
+ int s = lua_pcall(LuaState, (TableRef == LUA_REFNIL ? 1 : 2), 1, 0); \
+ if (report_errors(LuaState, s)) \
+ { \
+ return true; /* Abort enumeration */ \
+ } \
+ \
+ if (lua_isboolean(LuaState, -1)) \
+ { \
+ return (tolua_toboolean( LuaState, -1, 0) > 0); \
+ } \
+ return false; /* Continue enumeration */ \
+ } \
+ lua_State * LuaState; \
+ int FuncRef; \
+ int TableRef; \
+ } Callback(tolua_S, FuncRef, TableRef); \
+ \
+ bool bRetVal = self->FOREACH(Callback); \
+ \
+ /* Unreference the values again, so the LUA_REGISTRYINDEX can make place for other references */ \
+ luaL_unref(tolua_S, LUA_REGISTRYINDEX, TableRef); \
+ luaL_unref(tolua_S, LUA_REGISTRYINDEX, FuncRef); \
+ \
+ /* Push return value on stack */ \
+ tolua_pushboolean(tolua_S, bRetVal ); \
+ return 1; \
}
-
-static int tolua_cWorld_ForEachPlayer(lua_State* tolua_S)
-{
- int NumArgs = lua_gettop( tolua_S )-1; // This includes 'self'
- if( NumArgs != 1 && NumArgs != 2)
- {
- LOGWARN("Error in function call 'ForEachPlayer': Requires 1 or 2 arguments, got %i", NumArgs );
- return 0;
- }
-
- cWorld* self = (cWorld*) tolua_tousertype(tolua_S,1,0);
-
- if( !lua_isfunction( tolua_S, 2 ) )
- {
- LOGWARN("Error in function call 'ForEachPlayer': Expected a function for parameter #1");
- return 0;
- }
-
- // luaL_ref gets reference to value on top of the stack, the table is the last argument and therefore on the top
- int TableRef = LUA_REFNIL;
- if( NumArgs == 2 )
- {
- TableRef = luaL_ref(tolua_S, LUA_REGISTRYINDEX);
- if( TableRef == LUA_REFNIL )
- {
- LOGWARN("Error in function call 'ForEachPlayer': Could not get value reference of parameter #2");
- return 0;
- }
- }
-
- // table value is popped, and now function is on top of the stack
- int FuncRef = luaL_ref(tolua_S, LUA_REGISTRYINDEX);
- if( FuncRef == LUA_REFNIL )
- {
- LOGWARN("Error in function call 'ForEachPlayer': Could not get function reference of parameter #1");
- return 0;
- }
-
- class cLuaPlayerCallback : public cPlayerListCallback
- {
- public:
- cLuaPlayerCallback( lua_State* a_LuaState, int a_FuncRef, int a_TableRef )
- : LuaState( a_LuaState )
- , FuncRef( a_FuncRef )
- , TableRef( a_TableRef )
- {}
-
- private:
- virtual bool Item(cPlayer * a_Player) override
- {
- lua_rawgeti( LuaState, LUA_REGISTRYINDEX, FuncRef); // Push function reference
- tolua_pushusertype( LuaState, a_Player, "cPlayer" );
- if( TableRef != LUA_REFNIL )
- {
- lua_rawgeti( LuaState, LUA_REGISTRYINDEX, TableRef); // Push table reference
- }
-
- int s = lua_pcall( LuaState, (TableRef==LUA_REFNIL?1:2), 1, 0);
- if( report_errors( LuaState, s ) )
- {
- return true; // Abort enumeration
- }
-
- if( lua_isboolean( LuaState, -1 ) )
- {
- return (tolua_toboolean( LuaState, -1, 0) > 0);
- }
- return false; // Continue enumeration
- }
- lua_State * LuaState;
- int FuncRef;
- int TableRef;
- } Callback( tolua_S, FuncRef, TableRef );
-
- bool bRetVal = self->ForEachPlayer( Callback );
-
- // Unreference the values again, so the LUA_REGISTRYINDEX can make place for other references
- luaL_unref( tolua_S, LUA_REGISTRYINDEX, TableRef );
- luaL_unref( tolua_S, LUA_REGISTRYINDEX, FuncRef );
-
- // Push return value on stack
- tolua_pushboolean( tolua_S, bRetVal );
- return 1;
-}
+// Define the ForEach enumerators:
+DEFINE_LUA_FOREACH(cWorld,cPlayer,ForEachPlayer, tolua_cWorld_ForEachPlayer);
+DEFINE_LUA_FOREACH(cRoot, cWorld, ForEachWorld, tolua_cRoot_ForEachWorld);