Navigation Menu

Skip to content

Commit

Permalink
Check argument types inside MetaDataRef Lua API (#7045)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 authored and SmallJoker committed Feb 18, 2018
1 parent 46bbace commit 3f2e0c1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/script/lua_api/l_metadata.cpp
Expand Up @@ -95,7 +95,7 @@ int MetaDataRef::l_get_int(lua_State *L)
MAP_LOCK_REQUIRED;

MetaDataRef *ref = checkobject(L, 1);
std::string name = lua_tostring(L, 2);
std::string name = luaL_checkstring(L, 2);

Metadata *meta = ref->getmeta(false);
if (meta == NULL) {
Expand All @@ -114,8 +114,8 @@ int MetaDataRef::l_set_int(lua_State *L)
MAP_LOCK_REQUIRED;

MetaDataRef *ref = checkobject(L, 1);
std::string name = lua_tostring(L, 2);
int a = lua_tointeger(L, 3);
std::string name = luaL_checkstring(L, 2);
int a = luaL_checkint(L, 3);
std::string str = itos(a);

Metadata *meta = ref->getmeta(true);
Expand All @@ -133,7 +133,7 @@ int MetaDataRef::l_get_float(lua_State *L)
MAP_LOCK_REQUIRED;

MetaDataRef *ref = checkobject(L, 1);
std::string name = lua_tostring(L, 2);
std::string name = luaL_checkstring(L, 2);

Metadata *meta = ref->getmeta(false);
if (meta == NULL) {
Expand All @@ -152,8 +152,8 @@ int MetaDataRef::l_set_float(lua_State *L)
MAP_LOCK_REQUIRED;

MetaDataRef *ref = checkobject(L, 1);
std::string name = lua_tostring(L, 2);
float a = lua_tonumber(L, 3);
std::string name = luaL_checkstring(L, 2);
float a = luaL_checknumber(L, 3);
std::string str = ftos(a);

Metadata *meta = ref->getmeta(true);
Expand Down
2 changes: 1 addition & 1 deletion src/script/lua_api/l_nodemeta.cpp
Expand Up @@ -159,7 +159,7 @@ bool NodeMetaRef::handleFromTable(lua_State *L, int table, Metadata *_meta)
lua_pushnil(L);
while (lua_next(L, inventorytable) != 0) {
// key at index -2 and value at index -1
std::string name = lua_tostring(L, -2);
std::string name = luaL_checkstring(L, -2);
read_inventory_list(L, -1, inv, name.c_str(), getServer(L));
lua_pop(L, 1); // Remove value, keep key for next iteration
}
Expand Down

0 comments on commit 3f2e0c1

Please sign in to comment.