cLuaState: Added template to push multiple values in a single call. (#3331)
This commit is contained in:
parent
2f11655f00
commit
d4aff474c2
@ -12,11 +12,12 @@ If owning a state, trying to attach a state will automatically close the previou
|
||||
Calling a Lua function is done internally by pushing the function using PushFunction(), then pushing the
|
||||
arguments and finally executing CallFunction(). cLuaState automatically keeps track of the number of
|
||||
arguments and the name of the function (for logging purposes). After the call the return values are read from
|
||||
the stack using GetStackValue(). All of this is wrapped in a templated function overloads cLuaState::Call(),
|
||||
which is generated automatically by gen_LuaState_Call.lua script file into the LuaState_Call.inc file.
|
||||
the stack using GetStackValue(). All of this is wrapped in a templated function overloads cLuaState::Call().
|
||||
|
||||
Reference management is provided by the cLuaState::cRef class. This is used when you need to hold a reference to
|
||||
any Lua object across several function calls. The class is RAII-like, with automatic resource management.
|
||||
any Lua object across several function calls. The class is RAII-like, with automatic resource management. Note
|
||||
that the cRef object is not inherently thread-safe and is not notified when its cLuaState is closed. For those
|
||||
purposes, cTrackedRef can be used.
|
||||
|
||||
Callbacks management is provided by the cLuaState::cCallback class. Use a GetStackValue() with cCallbackPtr
|
||||
parameter to store the callback, and then at any time you can use the cCallback's Call() templated function
|
||||
@ -462,6 +463,14 @@ public:
|
||||
/** Returns true if a_FunctionName is a valid Lua function that can be called */
|
||||
bool HasFunction(const char * a_FunctionName);
|
||||
|
||||
/** Pushes multiple arguments onto the Lua stack. */
|
||||
template <typename Arg1, typename Arg2, typename... Args>
|
||||
void Push(Arg1 && a_Arg1, Arg2 && a_Arg2, Args &&... a_Args)
|
||||
{
|
||||
Push(std::forward<Arg1>(a_Arg1));
|
||||
Push(std::forward<Arg2>(a_Arg2), std::forward<Args>(a_Args)...);
|
||||
}
|
||||
|
||||
void PushNil(void);
|
||||
|
||||
// Push a const value onto the stack (keep alpha-sorted):
|
||||
|
@ -2062,14 +2062,7 @@ static int tolua_cUrlParser_Parse(lua_State * a_LuaState)
|
||||
L.Push(res.second);
|
||||
return 2;
|
||||
}
|
||||
L.Push(scheme);
|
||||
L.Push(username);
|
||||
L.Push(password);
|
||||
L.Push(host);
|
||||
L.Push(port);
|
||||
L.Push(path);
|
||||
L.Push(query);
|
||||
L.Push(fragment);
|
||||
L.Push(scheme, username, password, host, port, path, query, fragment);
|
||||
return 8;
|
||||
}
|
||||
|
||||
@ -2110,10 +2103,7 @@ static int tolua_cUrlParser_ParseAuthorityPart(lua_State * a_LuaState)
|
||||
L.Push(res.second);
|
||||
return 2;
|
||||
}
|
||||
L.Push(username);
|
||||
L.Push(password);
|
||||
L.Push(host);
|
||||
L.Push(port);
|
||||
L.Push(username, password, host, port);
|
||||
return 4;
|
||||
}
|
||||
|
||||
@ -2976,9 +2966,7 @@ static int tolua_cRoot_GetFurnaceRecipe(lua_State * tolua_S)
|
||||
}
|
||||
|
||||
// Push the output, number of ticks and input as the three return values:
|
||||
L.Push(Recipe->Out);
|
||||
L.Push(Recipe->CookTime);
|
||||
L.Push(Recipe->In);
|
||||
L.Push(Recipe->Out, Recipe->CookTime, Recipe->In);
|
||||
return 3;
|
||||
}
|
||||
|
||||
@ -3141,12 +3129,7 @@ static int tolua_cBlockArea_GetNonAirCropRelCoords(lua_State * tolua_S)
|
||||
self->GetNonAirCropRelCoords(MinRelX, MinRelY, MinRelZ, MaxRelX, MaxRelY, MaxRelZ, IgnoreBlockType);
|
||||
|
||||
// Push the six crop coords:
|
||||
L.Push(MinRelX);
|
||||
L.Push(MinRelY);
|
||||
L.Push(MinRelZ);
|
||||
L.Push(MaxRelX);
|
||||
L.Push(MaxRelY);
|
||||
L.Push(MaxRelZ);
|
||||
L.Push(MinRelX, MinRelY, MinRelZ, MaxRelX, MaxRelY, MaxRelZ);
|
||||
return 6;
|
||||
}
|
||||
|
||||
@ -3405,8 +3388,7 @@ static int tolua_cBoundingBox_CalcLineIntersection(lua_State * a_LuaState)
|
||||
L.Push(res);
|
||||
if (res)
|
||||
{
|
||||
L.Push(lineCoeff);
|
||||
L.Push(blockFace);
|
||||
L.Push(lineCoeff, blockFace);
|
||||
return 3;
|
||||
}
|
||||
return 1;
|
||||
@ -3465,8 +3447,7 @@ static int tolua_cChunkDesc_GetBlockTypeMeta(lua_State * a_LuaState)
|
||||
BLOCKTYPE blockType;
|
||||
NIBBLETYPE blockMeta;
|
||||
self->GetBlockTypeMeta(relX, relY, relZ, blockType, blockMeta);
|
||||
L.Push(blockType);
|
||||
L.Push(blockMeta);
|
||||
L.Push(blockType, blockMeta);
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
@ -489,9 +489,7 @@ static int tolua_cRankManager_GetPlayerMsgVisuals(lua_State * L)
|
||||
}
|
||||
|
||||
// Push the results:
|
||||
S.Push(MsgPrefix);
|
||||
S.Push(MsgSuffix);
|
||||
S.Push(MsgNameColorCode);
|
||||
S.Push(MsgPrefix, MsgSuffix, MsgNameColorCode);
|
||||
return 3;
|
||||
}
|
||||
|
||||
@ -752,9 +750,7 @@ static int tolua_cRankManager_GetRankVisuals(lua_State * L)
|
||||
}
|
||||
|
||||
// Push the results:
|
||||
S.Push(MsgPrefix);
|
||||
S.Push(MsgSuffix);
|
||||
S.Push(MsgNameColorCode);
|
||||
S.Push(MsgPrefix, MsgSuffix, MsgNameColorCode);
|
||||
return 3;
|
||||
}
|
||||
|
||||
|
@ -296,10 +296,7 @@ static int tolua_cWorld_GetBlockInfo(lua_State * tolua_S)
|
||||
L.Push(res);
|
||||
if (res)
|
||||
{
|
||||
L.Push(BlockType);
|
||||
L.Push(BlockMeta);
|
||||
L.Push(BlockSkyLight);
|
||||
L.Push(BlockBlockLight);
|
||||
L.Push(BlockType, BlockMeta, BlockSkyLight, BlockBlockLight);
|
||||
return 5;
|
||||
}
|
||||
return 1;
|
||||
@ -345,8 +342,7 @@ static int tolua_cWorld_GetBlockTypeMeta(lua_State * tolua_S)
|
||||
L.Push(res);
|
||||
if (res)
|
||||
{
|
||||
L.Push(BlockType);
|
||||
L.Push(BlockMeta);
|
||||
L.Push(BlockType, BlockMeta);
|
||||
return 3;
|
||||
}
|
||||
return 1;
|
||||
@ -390,10 +386,7 @@ static int tolua_cWorld_GetSignLines(lua_State * tolua_S)
|
||||
L.Push(res);
|
||||
if (res)
|
||||
{
|
||||
L.Push(Line1);
|
||||
L.Push(Line2);
|
||||
L.Push(Line3);
|
||||
L.Push(Line4);
|
||||
L.Push(Line1, Line2, Line3, Line4);
|
||||
return 5;
|
||||
}
|
||||
return 1;
|
||||
|
Loading…
Reference in New Issue
Block a user