From eef62c82a2e58700fc1216b0b8c03e421bc77995 Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Sat, 30 Jun 2018 17:11:38 +0200 Subject: Modernize lua read (part 2 & 3): C++ templating assurance (#7410) * Modernize lua read (part 2 & 3): C++ templating assurance Implement the boolean reader Implement the string reader Also remove unused & unimplemented script_error_handler Add a reader with default value --- src/script/cpp_api/s_client.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'src/script/cpp_api/s_client.cpp') diff --git a/src/script/cpp_api/s_client.cpp b/src/script/cpp_api/s_client.cpp index 7be4fc6a9..597883c2f 100644 --- a/src/script/cpp_api/s_client.cpp +++ b/src/script/cpp_api/s_client.cpp @@ -57,8 +57,7 @@ bool ScriptApiClient::on_sending_message(const std::string &message) // Call callbacks lua_pushstring(L, message.c_str()); runCallbacks(1, RUN_CALLBACKS_MODE_OR_SC); - bool ate = lua_toboolean(L, -1); - return ate; + return readParam(L, -1); } bool ScriptApiClient::on_receiving_message(const std::string &message) @@ -71,8 +70,7 @@ bool ScriptApiClient::on_receiving_message(const std::string &message) // Call callbacks lua_pushstring(L, message.c_str()); runCallbacks(1, RUN_CALLBACKS_MODE_OR_SC); - bool ate = lua_toboolean(L, -1); - return ate; + return readParam(L, -1); } void ScriptApiClient::on_damage_taken(int32_t damage_amount) @@ -186,8 +184,7 @@ bool ScriptApiClient::on_punchnode(v3s16 p, MapNode node) // Call functions runCallbacks(2, RUN_CALLBACKS_MODE_OR); - bool blocked = lua_toboolean(L, -1); - return blocked; + return readParam(L, -1); } bool ScriptApiClient::on_placenode(const PointedThing &pointed, const ItemDefinition &item) @@ -204,7 +201,7 @@ bool ScriptApiClient::on_placenode(const PointedThing &pointed, const ItemDefini // Call functions runCallbacks(2, RUN_CALLBACKS_MODE_OR); - return lua_toboolean(L, -1); + return readParam(L, -1); } bool ScriptApiClient::on_item_use(const ItemStack &item, const PointedThing &pointed) @@ -221,7 +218,7 @@ bool ScriptApiClient::on_item_use(const ItemStack &item, const PointedThing &poi // Call functions runCallbacks(2, RUN_CALLBACKS_MODE_OR); - return lua_toboolean(L, -1); + return readParam(L, -1); } bool ScriptApiClient::on_inventory_open(Inventory *inventory) @@ -242,7 +239,7 @@ bool ScriptApiClient::on_inventory_open(Inventory *inventory) } runCallbacks(1, RUN_CALLBACKS_MODE_OR); - return lua_toboolean(L, -1); + return readParam(L, -1); } void ScriptApiClient::setEnv(ClientEnvironment *env) -- cgit v1.2.3