From 11682d1386299d78bab39f77884797981950edee Mon Sep 17 00:00:00 2001 From: Mattes D Date: Tue, 16 Aug 2016 14:05:03 +0200 Subject: cLuaState: Moved function param counting to PushCallPop() template. The Push() functions can be used not only for function params, but also returns or temporaries, so it doesn't make sense to count the params there. --- src/Bindings/BindingsProcessor.lua | 1 - src/Bindings/LuaState.cpp | 27 --------------------------- src/Bindings/LuaState.h | 2 ++ 3 files changed, 2 insertions(+), 28 deletions(-) (limited to 'src/Bindings') diff --git a/src/Bindings/BindingsProcessor.lua b/src/Bindings/BindingsProcessor.lua index f936d3a68..df479a634 100644 --- a/src/Bindings/BindingsProcessor.lua +++ b/src/Bindings/BindingsProcessor.lua @@ -234,7 +234,6 @@ local function OutputLuaStateHelpers(a_Package) if not(g_HasCustomPushImplementation[item.name]) then f:write("void cLuaState::Push(" .. item.name .. " * a_Value)\n{\n\tASSERT(IsValid());\n") f:write("\ttolua_pushusertype(m_LuaState, a_Value, \"" .. item.name .. "\");\n"); - f:write("\tm_NumCurrentFunctionArgs += 1;\n") f:write("}\n\n\n\n\n\n") end end diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 2e1415519..ec6bdb48a 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -757,7 +757,6 @@ void cLuaState::Push(const AString & a_String) ASSERT(IsValid()); lua_pushlstring(m_LuaState, a_String.data(), a_String.size()); - m_NumCurrentFunctionArgs += 1; } @@ -794,7 +793,6 @@ void cLuaState::Push(const AStringVector & a_Vector) tolua_pushstring(m_LuaState, itr->c_str()); lua_rawseti(m_LuaState, newTable, index); } - m_NumCurrentFunctionArgs += 1; } @@ -806,7 +804,6 @@ void cLuaState::Push(const cCraftingGrid * a_Grid) ASSERT(IsValid()); tolua_pushusertype(m_LuaState, reinterpret_cast(const_cast(a_Grid)), "cCraftingGrid"); - m_NumCurrentFunctionArgs += 1; } @@ -818,7 +815,6 @@ void cLuaState::Push(const cCraftingRecipe * a_Recipe) ASSERT(IsValid()); tolua_pushusertype(m_LuaState, reinterpret_cast(const_cast(a_Recipe)), "cCraftingRecipe"); - m_NumCurrentFunctionArgs += 1; } @@ -830,7 +826,6 @@ void cLuaState::Push(const char * a_Value) ASSERT(IsValid()); tolua_pushstring(m_LuaState, a_Value); - m_NumCurrentFunctionArgs += 1; } @@ -842,7 +837,6 @@ void cLuaState::Push(const cItems & a_Items) ASSERT(IsValid()); tolua_pushusertype(m_LuaState, reinterpret_cast(const_cast(&a_Items)), "cItems"); - m_NumCurrentFunctionArgs += 1; } @@ -854,7 +848,6 @@ void cLuaState::Push(const cNil & a_Nil) ASSERT(IsValid()); lua_pushnil(m_LuaState); - m_NumCurrentFunctionArgs += 1; } @@ -866,7 +859,6 @@ void cLuaState::Push(const cPlayer * a_Player) ASSERT(IsValid()); tolua_pushusertype(m_LuaState, reinterpret_cast(const_cast(a_Player)), "cPlayer"); - m_NumCurrentFunctionArgs += 1; } @@ -878,7 +870,6 @@ void cLuaState::Push(const cLuaState::cRef & a_Ref) ASSERT(IsValid()); lua_rawgeti(m_LuaState, LUA_REGISTRYINDEX, static_cast(a_Ref)); - m_NumCurrentFunctionArgs += 1; } @@ -890,7 +881,6 @@ void cLuaState::Push(const HTTPRequest * a_Request) ASSERT(IsValid()); tolua_pushusertype(m_LuaState, reinterpret_cast(const_cast(a_Request)), "HTTPRequest"); - m_NumCurrentFunctionArgs += 1; } @@ -902,7 +892,6 @@ void cLuaState::Push(const HTTPTemplateRequest * a_Request) ASSERT(IsValid()); tolua_pushusertype(m_LuaState, reinterpret_cast(const_cast(a_Request)), "HTTPTemplateRequest"); - m_NumCurrentFunctionArgs += 1; } @@ -914,7 +903,6 @@ void cLuaState::Push(const Vector3d & a_Vector) ASSERT(IsValid()); tolua_pushusertype(m_LuaState, reinterpret_cast(const_cast(&a_Vector)), "Vector3"); - m_NumCurrentFunctionArgs += 1; } @@ -926,7 +914,6 @@ void cLuaState::Push(const Vector3d * a_Vector) ASSERT(IsValid()); tolua_pushusertype(m_LuaState, reinterpret_cast(const_cast(a_Vector)), "Vector3"); - m_NumCurrentFunctionArgs += 1; } @@ -938,7 +925,6 @@ void cLuaState::Push(const Vector3i & a_Vector) ASSERT(IsValid()); tolua_pushusertype(m_LuaState, reinterpret_cast(const_cast(&a_Vector)), "Vector3"); - m_NumCurrentFunctionArgs += 1; } @@ -950,7 +936,6 @@ void cLuaState::Push(const Vector3i * a_Vector) ASSERT(IsValid()); tolua_pushusertype(m_LuaState, reinterpret_cast(const_cast(a_Vector)), "Vector3"); - m_NumCurrentFunctionArgs += 1; } @@ -962,7 +947,6 @@ void cLuaState::Push(bool a_Value) ASSERT(IsValid()); tolua_pushboolean(m_LuaState, a_Value ? 1 : 0); - m_NumCurrentFunctionArgs += 1; } @@ -1027,8 +1011,6 @@ void cLuaState::Push(cEntity * a_Entity) } } // switch (EntityType) } - - m_NumCurrentFunctionArgs += 1; } @@ -1040,7 +1022,6 @@ void cLuaState::Push(cLuaServerHandle * a_ServerHandle) ASSERT(IsValid()); tolua_pushusertype(m_LuaState, a_ServerHandle, "cServerHandle"); - m_NumCurrentFunctionArgs += 1; } @@ -1052,7 +1033,6 @@ void cLuaState::Push(cLuaTCPLink * a_TCPLink) ASSERT(IsValid()); tolua_pushusertype(m_LuaState, a_TCPLink, "cTCPLink"); - m_NumCurrentFunctionArgs += 1; } @@ -1064,7 +1044,6 @@ void cLuaState::Push(cLuaUDPEndpoint * a_UDPEndpoint) ASSERT(IsValid()); tolua_pushusertype(m_LuaState, a_UDPEndpoint, "cUDPEndpoint"); - m_NumCurrentFunctionArgs += 1; } @@ -1076,7 +1055,6 @@ void cLuaState::Push(double a_Value) ASSERT(IsValid()); tolua_pushnumber(m_LuaState, a_Value); - m_NumCurrentFunctionArgs += 1; } @@ -1088,7 +1066,6 @@ void cLuaState::Push(int a_Value) ASSERT(IsValid()); tolua_pushnumber(m_LuaState, a_Value); - m_NumCurrentFunctionArgs += 1; } @@ -1100,7 +1077,6 @@ void cLuaState::Push(long a_Value) ASSERT(IsValid()); tolua_pushnumber(m_LuaState, static_cast(a_Value)); - m_NumCurrentFunctionArgs += 1; } @@ -1112,7 +1088,6 @@ void cLuaState::Push(UInt32 a_Value) ASSERT(IsValid()); tolua_pushnumber(m_LuaState, a_Value); - m_NumCurrentFunctionArgs += 1; } @@ -1124,7 +1099,6 @@ void cLuaState::Push(std::chrono::milliseconds a_Value) ASSERT(IsValid()); tolua_pushnumber(m_LuaState, static_cast(a_Value.count())); - m_NumCurrentFunctionArgs += 1; } @@ -1136,7 +1110,6 @@ void cLuaState::Pop(int a_NumValuesToPop) ASSERT(IsValid()); lua_pop(m_LuaState, a_NumValuesToPop); - m_NumCurrentFunctionArgs -= a_NumValuesToPop; } diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index 3c07ac5d2..cb68b9a98 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -634,6 +634,7 @@ public: template bool Call(const FnT & a_Function, Args &&... args) { + m_NumCurrentFunctionArgs = -1; if (!PushFunction(std::forward(a_Function))) { // Pushing the function failed @@ -795,6 +796,7 @@ protected: inline bool PushCallPop(T && a_Param, Args &&... args) { Push(std::forward(a_Param)); + m_NumCurrentFunctionArgs += 1; return PushCallPop(std::forward(args)...); } -- cgit v1.2.3