mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-11-25 21:45:12 +00:00
Check hook return types before using them
This commit is contained in:
parent
a31ddaff9d
commit
c25bf4c8d3
2 changed files with 11 additions and 5 deletions
|
@ -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; }
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue