mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2026-06-08 17:11:40 +00:00
add guards to smlua__iter lot types
Some checks are pending
Some checks are pending
Resolves #1257
This commit is contained in:
parent
7ed28bf411
commit
a8da02aae1
1 changed files with 15 additions and 9 deletions
|
|
@ -49,7 +49,14 @@ struct LuaObjectField* smlua_get_object_field_from_ot(struct LuaObjectTable* ot,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
struct LuaObjectField* smlua_get_object_field(u16 lot, const char* key) {
|
||||
bool smlua_valid_lot(u16 lot) {
|
||||
if (lot > LOT_NONE && lot < LOT_MAX) { return true; }
|
||||
if (lot > LOT_AUTOGEN_MIN && lot < LOT_AUTOGEN_MAX) { return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
struct LuaObjectField *smlua_get_object_field(u16 lot, const char* key) {
|
||||
if (!smlua_valid_lot(lot)) { return NULL; }
|
||||
if (lot > LOT_AUTOGEN_MIN) {
|
||||
return smlua_get_object_field_autogen(lot, key);
|
||||
}
|
||||
|
|
@ -58,12 +65,6 @@ struct LuaObjectField* smlua_get_object_field(u16 lot, const char* key) {
|
|||
return smlua_get_object_field_from_ot(ot, key);
|
||||
}
|
||||
|
||||
bool smlua_valid_lot(u16 lot) {
|
||||
if (lot > LOT_NONE && lot < LOT_MAX) { return true; }
|
||||
if (lot > LOT_AUTOGEN_MIN && lot < LOT_AUTOGEN_MAX) { return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
bool smlua_valid_lvt(u16 lvt) {
|
||||
return (lvt < LVT_MAX);
|
||||
}
|
||||
|
|
@ -684,11 +685,16 @@ int smlua__iter(lua_State *L) {
|
|||
lua_rawgeti(L, 1, 2);
|
||||
const CObject *cobj = lua_touserdata(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
|
||||
// Only support autogen objects
|
||||
if (cobj->lot <= LOT_AUTOGEN_MIN || cobj->lot >= LOT_AUTOGEN_MAX) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern struct LuaObjectTable sLuaObjectAutogenTable[];
|
||||
struct LuaObjectTable* ot = &sLuaObjectAutogenTable[cobj->lot - LOT_AUTOGEN_MIN - 1];
|
||||
if (i >= ot->fieldCount) { return 0; }
|
||||
|
||||
|
||||
u8* pointer = (u8*)(intptr_t) cobj->pointer;
|
||||
struct LuaObjectField* data = &ot->fields[i];
|
||||
lua_pushstring(L, data->key);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue