add help in cobject arrays for 0 indexed accesses

in case people try to access the array starting at 0
This commit is contained in:
Isaac0-dev 2025-02-21 09:37:31 +10:00
parent f4b79bc7a4
commit d71ef89dbb

View file

@ -438,8 +438,9 @@ static int smlua__get_field(lua_State* L) {
return 0; return 0;
} }
u32 key = lua_tointeger(L, 2); int isNum;
if (!key) { u32 key = lua_tointegerx(L, 2, &isNum);
if (!isNum) {
const char *key = lua_tostring(L, 2); const char *key = lua_tostring(L, 2);
if (key && key[0] == '_') { if (key && key[0] == '_') {
if (strcmp(key, "_lot") == 0) { if (strcmp(key, "_lot") == 0) {
@ -455,6 +456,11 @@ static int smlua__get_field(lua_State* L) {
return 0; return 0;
} }
if (key == 0) {
LOG_LUA_LINE("Key is out of bounds for array: key '%u' (help: array starts at 1)", key);
return 0;
}
key--; // Lua is +1 indexed key--; // Lua is +1 indexed
if (key >= data->count) { if (key >= data->count) {
LOG_LUA_LINE("Key is out of bounds for array: key '%u'", key); LOG_LUA_LINE("Key is out of bounds for array: key '%u'", key);