summaryrefslogtreecommitdiff
path: root/src/script/cpp_api/s_client.cpp
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2018-06-30 17:11:38 +0200
committerGitHub <noreply@github.com>2018-06-30 17:11:38 +0200
commiteef62c82a2e58700fc1216b0b8c03e421bc77995 (patch)
tree4c49e659069036cb53d69535dc33d33f29d963f4 /src/script/cpp_api/s_client.cpp
parent227c71eb76e019873b30e2d3893b68307d51d58f (diff)
downloadminetest-eef62c82a2e58700fc1216b0b8c03e421bc77995.tar.gz
minetest-eef62c82a2e58700fc1216b0b8c03e421bc77995.tar.bz2
minetest-eef62c82a2e58700fc1216b0b8c03e421bc77995.zip
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
Diffstat (limited to 'src/script/cpp_api/s_client.cpp')
-rw-r--r--src/script/cpp_api/s_client.cpp15
1 files changed, 6 insertions, 9 deletions
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<bool>(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<bool>(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<bool>(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<bool>(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<bool>(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<bool>(L, -1);
}
void ScriptApiClient::setEnv(ClientEnvironment *env)