Skip to content

Commit 3f2e0c1

Browse files
sfan5SmallJoker
authored andcommittedFeb 18, 2018
Check argument types inside MetaDataRef Lua API (#7045)
1 parent 46bbace commit 3f2e0c1

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed
 

Diff for: ‎src/script/lua_api/l_metadata.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ int MetaDataRef::l_get_int(lua_State *L)
9595
MAP_LOCK_REQUIRED;
9696

9797
MetaDataRef *ref = checkobject(L, 1);
98-
std::string name = lua_tostring(L, 2);
98+
std::string name = luaL_checkstring(L, 2);
9999

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

116116
MetaDataRef *ref = checkobject(L, 1);
117-
std::string name = lua_tostring(L, 2);
118-
int a = lua_tointeger(L, 3);
117+
std::string name = luaL_checkstring(L, 2);
118+
int a = luaL_checkint(L, 3);
119119
std::string str = itos(a);
120120

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

135135
MetaDataRef *ref = checkobject(L, 1);
136-
std::string name = lua_tostring(L, 2);
136+
std::string name = luaL_checkstring(L, 2);
137137

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

154154
MetaDataRef *ref = checkobject(L, 1);
155-
std::string name = lua_tostring(L, 2);
156-
float a = lua_tonumber(L, 3);
155+
std::string name = luaL_checkstring(L, 2);
156+
float a = luaL_checknumber(L, 3);
157157
std::string str = ftos(a);
158158

159159
Metadata *meta = ref->getmeta(true);

Diff for: ‎src/script/lua_api/l_nodemeta.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ bool NodeMetaRef::handleFromTable(lua_State *L, int table, Metadata *_meta)
159159
lua_pushnil(L);
160160
while (lua_next(L, inventorytable) != 0) {
161161
// key at index -2 and value at index -1
162-
std::string name = lua_tostring(L, -2);
162+
std::string name = luaL_checkstring(L, -2);
163163
read_inventory_list(L, -1, inv, name.c_str(), getServer(L));
164164
lua_pop(L, 1); // Remove value, keep key for next iteration
165165
}

0 commit comments

Comments
 (0)
Please sign in to comment.