summaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_inventory.cpp
diff options
context:
space:
mode:
authorSmallJoker <SmallJoker@users.noreply.github.com>2020-04-27 07:02:39 +0200
committerGitHub <noreply@github.com>2020-04-27 07:02:39 +0200
commitbe71e70a91a3c857652a8b037dac7adf9d0fcdd1 (patch)
treeec16ade79fa9c458eb184b2d5b92ce106ec2d4b6 /src/script/lua_api/l_inventory.cpp
parent515d38a702f0ebe1f419ce38c86484ecb845ed36 (diff)
downloadminetest-be71e70a91a3c857652a8b037dac7adf9d0fcdd1.tar.gz
minetest-be71e70a91a3c857652a8b037dac7adf9d0fcdd1.tar.bz2
minetest-be71e70a91a3c857652a8b037dac7adf9d0fcdd1.zip
Script: Enforce type checks if not nil (#9748)
* Script: Enforce type checks if not nil
Diffstat (limited to 'src/script/lua_api/l_inventory.cpp')
-rw-r--r--src/script/lua_api/l_inventory.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/script/lua_api/l_inventory.cpp b/src/script/lua_api/l_inventory.cpp
index 6e7afa4a4..4c8977898 100644
--- a/src/script/lua_api/l_inventory.cpp
+++ b/src/script/lua_api/l_inventory.cpp
@@ -487,7 +487,9 @@ int ModApiInventory::l_get_inventory(lua_State *L)
{
InventoryLocation loc;
- std::string type = checkstringfield(L, 1, "type");
+ lua_getfield(L, 1, "type");
+ std::string type = luaL_checkstring(L, -1);
+ lua_pop(L, 1);
if(type == "node"){
MAP_LOCK_REQUIRED;
@@ -504,11 +506,13 @@ int ModApiInventory::l_get_inventory(lua_State *L)
NO_MAP_LOCK_REQUIRED;
if (type == "player") {
- std::string name = checkstringfield(L, 1, "name");
- loc.setPlayer(name);
+ lua_getfield(L, 1, "name");
+ loc.setPlayer(luaL_checkstring(L, -1));
+ lua_pop(L, 1);
} else if (type == "detached") {
- std::string name = checkstringfield(L, 1, "name");
- loc.setDetached(name);
+ lua_getfield(L, 1, "name");
+ loc.setDetached(luaL_checkstring(L, -1));
+ lua_pop(L, 1);
}
if (getServer(L)->getInventory(loc) != NULL)