1
0

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.
This commit is contained in:
Mattes D 2016-08-16 14:05:03 +02:00
parent 9493488e48
commit 11682d1386
3 changed files with 2 additions and 28 deletions

View File

@ -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

View File

@ -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<void *>(const_cast<cCraftingGrid *>(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<void *>(const_cast<cCraftingRecipe *>(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<void *>(const_cast<cItems *>(&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<void *>(const_cast<cPlayer *>(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<int>(a_Ref));
m_NumCurrentFunctionArgs += 1;
}
@ -890,7 +881,6 @@ void cLuaState::Push(const HTTPRequest * a_Request)
ASSERT(IsValid());
tolua_pushusertype(m_LuaState, reinterpret_cast<void *>(const_cast<HTTPRequest *>(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<void *>(const_cast<HTTPTemplateRequest *>(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<void *>(const_cast<Vector3d *>(&a_Vector)), "Vector3<double>");
m_NumCurrentFunctionArgs += 1;
}
@ -926,7 +914,6 @@ void cLuaState::Push(const Vector3d * a_Vector)
ASSERT(IsValid());
tolua_pushusertype(m_LuaState, reinterpret_cast<void *>(const_cast<Vector3d *>(a_Vector)), "Vector3<double>");
m_NumCurrentFunctionArgs += 1;
}
@ -938,7 +925,6 @@ void cLuaState::Push(const Vector3i & a_Vector)
ASSERT(IsValid());
tolua_pushusertype(m_LuaState, reinterpret_cast<void *>(const_cast<Vector3i *>(&a_Vector)), "Vector3<int>");
m_NumCurrentFunctionArgs += 1;
}
@ -950,7 +936,6 @@ void cLuaState::Push(const Vector3i * a_Vector)
ASSERT(IsValid());
tolua_pushusertype(m_LuaState, reinterpret_cast<void *>(const_cast<Vector3i *>(a_Vector)), "Vector3<int>");
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<lua_Number>(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<lua_Number>(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;
}

View File

@ -634,6 +634,7 @@ public:
template <typename FnT, typename... Args>
bool Call(const FnT & a_Function, Args &&... args)
{
m_NumCurrentFunctionArgs = -1;
if (!PushFunction(std::forward<const FnT &>(a_Function)))
{
// Pushing the function failed
@ -795,6 +796,7 @@ protected:
inline bool PushCallPop(T && a_Param, Args &&... args)
{
Push(std::forward<T>(a_Param));
m_NumCurrentFunctionArgs += 1;
return PushCallPop(std::forward<Args>(args)...);
}