fix(lua): stricter type check when calling API function (#16745)

Solves #13651

Co-authored-by: Gregory Anders <greg@gpanders.com>
This commit is contained in:
dundargoc
2022-01-03 16:00:50 +01:00
committed by GitHub
parent 76435c0cfa
commit 297ff97647
2 changed files with 8 additions and 1 deletions

View File

@@ -1242,7 +1242,12 @@ LuaRef nlua_pop_LuaRef(lua_State *const lstate, Error *err)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT \
{ \
type ret; \
ret = (type)lua_tonumber(lstate, -1); \
if (lua_type(lstate, -1) != LUA_TNUMBER) { \
api_set_error(err, kErrorTypeValidation, "Expected Lua number"); \
ret = (type)-1; \
} else { \
ret = (type)lua_tonumber(lstate, -1); \
} \
lua_pop(lstate, 1); \
return ret; \
}