1
0

Refactored code to use cLuaState

Fixes #2377.
This commit is contained in:
Samuel Barney 2015-08-07 08:44:52 -06:00 committed by Mattes D
parent 6fdc4a1ea3
commit 4996e53bf5
2 changed files with 29 additions and 34 deletions

View File

@ -281,32 +281,29 @@ static int tolua_cWorld_SetSignLines(lua_State * tolua_S)
cLuaState LuaState(tolua_S);
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype (LuaState, 1, "cWorld", 0, &tolua_err) ||
!tolua_isnumber (LuaState, 2, 0, &tolua_err) ||
!tolua_isnumber (LuaState, 3, 0, &tolua_err) ||
!tolua_isnumber (LuaState, 4, 0, &tolua_err) ||
!tolua_iscppstring(LuaState, 5, 0, &tolua_err) ||
!tolua_iscppstring(LuaState, 6, 0, &tolua_err) ||
!tolua_iscppstring(LuaState, 7, 0, &tolua_err) ||
!tolua_iscppstring(LuaState, 8, 0, &tolua_err) ||
!tolua_isusertype (LuaState, 9, "cPlayer", 1, &tolua_err) ||
!tolua_isnoobj (LuaState, 10, &tolua_err)
!LuaState.CheckParamUserType(1, "cWorld") ||
!LuaState.CheckParamNumber(2, 4) ||
!LuaState.CheckParamString(5, 8) ||
!LuaState.CheckParamUserType(9, "cPlayer") ||
!LuaState.CheckParamEnd(10)
)
goto tolua_lerror;
return 0;
else
#endif
{
cWorld * self = reinterpret_cast<cWorld *>(tolua_tousertype (LuaState, 1, nullptr));
cPlayer * Player = reinterpret_cast<cPlayer*>(tolua_tousertype (LuaState, 9, nullptr));
int BlockX = static_cast<int>(tolua_tonumber(LuaState, 2, 0));
int BlockY = static_cast<int>(tolua_tonumber(LuaState, 3, 0));
int BlockZ = static_cast<int>(tolua_tonumber(LuaState, 4, 0));
const AString Line1 = tolua_tocppstring(LuaState, 5, 0);
const AString Line2 = tolua_tocppstring(LuaState, 6, 0);
const AString Line3 = tolua_tocppstring(LuaState, 7, 0);
const AString Line4 = tolua_tocppstring(LuaState, 8, 0);
cWorld * self = nullptr;
cPlayer * Player = nullptr;
int BlockX = 0;
int BlockY = 0;
int BlockZ = 0;
AString Line1;
AString Line2;
AString Line3;
AString Line4;
LuaState.GetStackValues(1, self, BlockX, BlockY, BlockZ, Line1, Line2, Line3, Line4, Player);
#ifndef TOLUA_RELEASE
if (self == nullptr)
{
@ -321,12 +318,6 @@ static int tolua_cWorld_SetSignLines(lua_State * tolua_S)
LOGWARNING("Warning in function call 'UpdateSign': UpdateSign() is deprecated. Please use SetSignLines()");
LuaState.LogStackTrace(0);
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(LuaState, "#ferror in function 'UpdateSign'.", &tolua_err);
return 0;
#endif
}

View File

@ -1313,23 +1313,27 @@ static int tolua_SetObjectCallback(lua_State * tolua_S)
static int tolua_cPluginLua_AddWebTab(lua_State * tolua_S)
{
cPluginLua * self = reinterpret_cast<cPluginLua *>(tolua_tousertype(tolua_S, 1, nullptr));
cLuaState LuaState(tolua_S);
cPluginLua * self = nullptr;
if (!LuaState.GetStackValue(1, self))
{
LOGWARNING("cPluginLua:AddWebTab: invalid self as first argument");
return 0;
}
tolua_Error tolua_err;
tolua_err.array = 0;
tolua_err.index = 3;
tolua_err.type = "function";
std::string Title = "";
std::string Title;
int Reference = LUA_REFNIL;
if (
tolua_isstring(tolua_S, 2, 0, &tolua_err) &&
lua_isfunction(tolua_S, 3)
)
if (LuaState.CheckParamString(2) && LuaState.CheckParamFunction(3))
{
Reference = luaL_ref(tolua_S, LUA_REGISTRYINDEX);
Title = (static_cast<std::string>(tolua_tocppstring(tolua_S, 2, 0)));
LuaState.GetStackValue(2, Title);
}
else
{