28 changes: 9 additions & 19 deletions src/script/cpp_api/s_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ bool ScriptApiNode::node_on_punch(v3s16 p, MapNode node,
pushnode(L, node, ndef);
objectrefGetOrCreate(L, puncher);
pushPointedThing(pointed);
if (lua_pcall(L, 4, 0, m_errorhandler))
scriptError();
PCALL_RES(lua_pcall(L, 4, 0, m_errorhandler));
return true;
}

Expand All @@ -126,8 +125,7 @@ bool ScriptApiNode::node_on_dig(v3s16 p, MapNode node,
push_v3s16(L, p);
pushnode(L, node, ndef);
objectrefGetOrCreate(L, digger);
if (lua_pcall(L, 3, 0, m_errorhandler))
scriptError();
PCALL_RES(lua_pcall(L, 3, 0, m_errorhandler));
return true;
}

Expand All @@ -143,8 +141,7 @@ void ScriptApiNode::node_on_construct(v3s16 p, MapNode node)

// Call function
push_v3s16(L, p);
if (lua_pcall(L, 1, 0, m_errorhandler))
scriptError();
PCALL_RES(lua_pcall(L, 1, 0, m_errorhandler));
}

void ScriptApiNode::node_on_destruct(v3s16 p, MapNode node)
Expand All @@ -159,8 +156,7 @@ void ScriptApiNode::node_on_destruct(v3s16 p, MapNode node)

// Call function
push_v3s16(L, p);
if (lua_pcall(L, 1, 0, m_errorhandler))
scriptError();
PCALL_RES(lua_pcall(L, 1, 0, m_errorhandler));
}

void ScriptApiNode::node_after_destruct(v3s16 p, MapNode node)
Expand All @@ -176,8 +172,7 @@ void ScriptApiNode::node_after_destruct(v3s16 p, MapNode node)
// Call function
push_v3s16(L, p);
pushnode(L, node, ndef);
if (lua_pcall(L, 2, 0, m_errorhandler))
scriptError();
PCALL_RES(lua_pcall(L, 2, 0, m_errorhandler));
}

bool ScriptApiNode::node_on_timer(v3s16 p, MapNode node, f32 dtime)
Expand All @@ -193,8 +188,7 @@ bool ScriptApiNode::node_on_timer(v3s16 p, MapNode node, f32 dtime)
// Call function
push_v3s16(L, p);
lua_pushnumber(L,dtime);
if (lua_pcall(L, 2, 1, m_errorhandler))
scriptError();
PCALL_RES(lua_pcall(L, 2, 1, m_errorhandler));
return (bool) lua_isboolean(L, -1) && (bool) lua_toboolean(L, -1) == true;
}

Expand Down Expand Up @@ -229,8 +223,7 @@ void ScriptApiNode::node_on_receive_fields(v3s16 p,
lua_settable(L, -3);
}
objectrefGetOrCreate(L, sender); // player
if (lua_pcall(L, 4, 0, m_errorhandler))
scriptError();
PCALL_RES(lua_pcall(L, 4, 0, m_errorhandler));
}

void ScriptApiNode::node_falling_update(v3s16 p)
Expand All @@ -239,8 +232,7 @@ void ScriptApiNode::node_falling_update(v3s16 p)

lua_getglobal(L, "nodeupdate");
push_v3s16(L, p);
if (lua_pcall(L, 1, 0, m_errorhandler))
scriptError();
PCALL_RES(lua_pcall(L, 1, 0, m_errorhandler));
}

void ScriptApiNode::node_falling_update_single(v3s16 p)
Expand All @@ -249,7 +241,5 @@ void ScriptApiNode::node_falling_update_single(v3s16 p)

lua_getglobal(L, "nodeupdate_single");
push_v3s16(L, p);
if (lua_pcall(L, 1, 0, m_errorhandler))
scriptError();
PCALL_RES(lua_pcall(L, 1, 0, m_errorhandler));
}

24 changes: 10 additions & 14 deletions src/script/cpp_api/s_nodemeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowMove(v3s16 p,
lua_pushinteger(L, to_index + 1); // to_index
lua_pushinteger(L, count); // count
objectrefGetOrCreate(L, player); // player
if (lua_pcall(L, 7, 1, m_errorhandler))
scriptError();
PCALL_RES(lua_pcall(L, 7, 1, m_errorhandler));
if (!lua_isnumber(L, -1))
throw LuaError("allow_metadata_inventory_move should"
" return a number, guilty node: " + nodename);
Expand Down Expand Up @@ -89,8 +88,7 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowPut(v3s16 p,
lua_pushinteger(L, index + 1); // index
LuaItemStack::create(L, stack); // stack
objectrefGetOrCreate(L, player); // player
if (lua_pcall(L, 5, 1, m_errorhandler))
scriptError();
PCALL_RES(lua_pcall(L, 5, 1, m_errorhandler));
if(!lua_isnumber(L, -1))
throw LuaError("allow_metadata_inventory_put should"
" return a number, guilty node: " + nodename);
Expand Down Expand Up @@ -124,8 +122,7 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowTake(v3s16 p,
lua_pushinteger(L, index + 1); // index
LuaItemStack::create(L, stack); // stack
objectrefGetOrCreate(L, player); // player
if (lua_pcall(L, 5, 1, m_errorhandler))
scriptError();
PCALL_RES(lua_pcall(L, 5, 1, m_errorhandler));
if (!lua_isnumber(L, -1))
throw LuaError("allow_metadata_inventory_take should"
" return a number, guilty node: " + nodename);
Expand Down Expand Up @@ -162,8 +159,7 @@ void ScriptApiNodemeta::nodemeta_inventory_OnMove(v3s16 p,
lua_pushinteger(L, to_index + 1); // to_index
lua_pushinteger(L, count); // count
objectrefGetOrCreate(L, player); // player
if (lua_pcall(L, 7, 0, m_errorhandler))
scriptError();
PCALL_RES(lua_pcall(L, 7, 0, m_errorhandler));
}

// Report put items
Expand Down Expand Up @@ -191,8 +187,7 @@ void ScriptApiNodemeta::nodemeta_inventory_OnPut(v3s16 p,
lua_pushinteger(L, index + 1); // index
LuaItemStack::create(L, stack); // stack
objectrefGetOrCreate(L, player); // player
if (lua_pcall(L, 5, 0, m_errorhandler))
scriptError();
PCALL_RES(lua_pcall(L, 5, 0, m_errorhandler));
}

// Report taken items
Expand Down Expand Up @@ -220,13 +215,14 @@ void ScriptApiNodemeta::nodemeta_inventory_OnTake(v3s16 p,
lua_pushinteger(L, index + 1); // index
LuaItemStack::create(L, stack); // stack
objectrefGetOrCreate(L, player); // player
if (lua_pcall(L, 5, 0, m_errorhandler))
scriptError();
PCALL_RES(lua_pcall(L, 5, 0, m_errorhandler));
}

ScriptApiNodemeta::ScriptApiNodemeta() {
ScriptApiNodemeta::ScriptApiNodemeta()
{
}

ScriptApiNodemeta::~ScriptApiNodemeta() {
ScriptApiNodemeta::~ScriptApiNodemeta()
{
}

3 changes: 1 addition & 2 deletions src/script/cpp_api/s_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ s16 ScriptApiPlayer::on_player_hpchange(ServerActiveObject *player,

objectrefGetOrCreate(L, player);
lua_pushnumber(L, hp_change);
if (lua_pcall(L, 2, 1, m_errorhandler))
scriptError();
PCALL_RES(lua_pcall(L, 2, 1, m_errorhandler));
hp_change = lua_tointeger(L, -1);
lua_pop(L, -1);
return hp_change;
Expand Down
9 changes: 3 additions & 6 deletions src/script/cpp_api/s_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ bool ScriptApiServer::getAuth(const std::string &playername,
if (lua_type(L, -1) != LUA_TFUNCTION)
throw LuaError("Authentication handler missing get_auth");
lua_pushstring(L, playername.c_str());
if (lua_pcall(L, 1, 1, m_errorhandler))
scriptError();
PCALL_RES(lua_pcall(L, 1, 1, m_errorhandler));
lua_remove(L, -2); // Remove auth handler

// nil = login not allowed
Expand Down Expand Up @@ -104,8 +103,7 @@ void ScriptApiServer::createAuth(const std::string &playername,
throw LuaError("Authentication handler missing create_auth");
lua_pushstring(L, playername.c_str());
lua_pushstring(L, password.c_str());
if (lua_pcall(L, 2, 0, m_errorhandler))
scriptError();
PCALL_RES(lua_pcall(L, 2, 0, m_errorhandler));
}

bool ScriptApiServer::setPassword(const std::string &playername,
Expand All @@ -120,8 +118,7 @@ bool ScriptApiServer::setPassword(const std::string &playername,
throw LuaError("Authentication handler missing set_password");
lua_pushstring(L, playername.c_str());
lua_pushstring(L, password.c_str());
if (lua_pcall(L, 2, 1, m_errorhandler))
scriptError();
PCALL_RES(lua_pcall(L, 2, 1, m_errorhandler));
return lua_toboolean(L, -1);
}

Expand Down
10 changes: 6 additions & 4 deletions src/script/lua_api/l_env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ void LuaABM::trigger(ServerEnvironment *env, v3s16 p, MapNode n,
pushnode(L, n, env->getGameDef()->ndef());
lua_pushnumber(L, active_object_count);
lua_pushnumber(L, active_object_count_wider);
if(lua_pcall(L, 4, 0, errorhandler))
script_error(L);

PCALL_RESL(L, lua_pcall(L, 4, 0, errorhandler));

lua_pop(L, 1); // Pop error handler
}

Expand Down Expand Up @@ -418,8 +419,9 @@ int ModApiEnvMod::l_add_item(lua_State *L)
return 0;
lua_pushvalue(L, 1);
lua_pushstring(L, item.getItemString().c_str());
if(lua_pcall(L, 2, 1, errorhandler))
script_error(L);

PCALL_RESL(L, lua_pcall(L, 2, 1, errorhandler));

lua_remove(L, errorhandler); // Remove error handler
return 1;
}
Expand Down
4 changes: 2 additions & 2 deletions src/script/scripting_game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void GameScripting::InitializeModApi(lua_State *L, int top)
LuaSettings::Register(L);
}

void log_deprecated(std::string message)
void log_deprecated(const std::string &message)
{
log_deprecated(NULL,message);
log_deprecated(NULL, message);
}
2 changes: 1 addition & 1 deletion src/script/scripting_game.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ class GameScripting :
void InitializeModApi(lua_State *L, int top);
};

void log_deprecated(std::string message);
void log_deprecated(const std::string &message);

#endif /* SCRIPTING_GAME_H_ */