Check hook return types before using them

This commit is contained in:
MysterD 2022-04-16 20:27:51 -07:00
parent a31ddaff9d
commit c25bf4c8d3
2 changed files with 11 additions and 5 deletions

View File

@ -440,11 +440,11 @@ bool smlua_call_action_hook(struct MarioState* m, s32* returnValue) {
}
// output the return value
*returnValue = smlua_to_integer(L, -1);
if (lua_type(L, -1) == LUA_TBOOLEAN || lua_type(L, -1) == LUA_TNUMBER) {
*returnValue = smlua_to_integer(L, -1);
}
lua_pop(L, 1);
if (!gSmLuaConvertSuccess) { return false; }
return true;
}
}
@ -753,7 +753,10 @@ bool smlua_call_chat_command_hook(char* command) {
}
// output the return value
bool returnValue = smlua_to_boolean(L, -1);
bool returnValue = false;
if (lua_type(L, -1) == LUA_TBOOLEAN) {
returnValue = smlua_to_boolean(L, -1);
}
lua_pop(L, 1);
if (!gSmLuaConvertSuccess) { return false; }

View File

@ -66,7 +66,10 @@ lua_Integer smlua_to_integer(lua_State* L, int index) {
}
lua_Number smlua_to_number(lua_State* L, int index) {
if (lua_type(L, index) != LUA_TNUMBER) {
if (lua_type(L, index) == LUA_TBOOLEAN) {
gSmLuaConvertSuccess = true;
return lua_toboolean(L, index) ? 1 : 0;
} else if (lua_type(L, index) != LUA_TNUMBER) {
LOG_LUA("smlua_to_number received improper type '%d'", lua_type(L, index));
smlua_logline();
gSmLuaConvertSuccess = false;