From 2dd17af4e1a6bae197754960e1fed71cb2f0a9cf Mon Sep 17 00:00:00 2001 From: Isaac0-dev <62234577+Isaac0-dev@users.noreply.github.com> Date: Fri, 14 Mar 2025 10:24:33 +1000 Subject: [PATCH] explicitly allow setting cobjects to nil --- src/pc/lua/smlua_cobject.c | 8 ++++++++ src/pc/lua/smlua_utils.c | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/pc/lua/smlua_cobject.c b/src/pc/lua/smlua_cobject.c index 13b034a33..c825a0f33 100644 --- a/src/pc/lua/smlua_cobject.c +++ b/src/pc/lua/smlua_cobject.c @@ -430,6 +430,10 @@ static bool smlua_set_field(lua_State* L, u8* p, struct LuaObjectField *data) { case LVT_U64: *(s64*)p = smlua_to_integer(L, 3); break; case LVT_COBJECT_P: + if (lua_isnil(L, 3)) { + *(u8**)p = NULL; + break; + } valuePointer = smlua_to_cobject(L, 3, data->lot); if (gSmLuaConvertSuccess) { *(u8**)p = valuePointer; @@ -450,6 +454,10 @@ static bool smlua_set_field(lua_State* L, u8* p, struct LuaObjectField *data) { case LVT_OBJECTANIMPOINTER_P: case LVT_COLLISION_P: case LVT_TRAJECTORY_P: + if (lua_isnil(L, 3)) { + *(u8**)p = NULL; + break; + } valuePointer = smlua_to_cpointer(L, 3, data->valueType); if (gSmLuaConvertSuccess) { *(u8**)p = valuePointer; diff --git a/src/pc/lua/smlua_utils.c b/src/pc/lua/smlua_utils.c index a7227db89..dfb7ef0fc 100644 --- a/src/pc/lua/smlua_utils.c +++ b/src/pc/lua/smlua_utils.c @@ -153,7 +153,7 @@ void* smlua_to_cobject(lua_State* L, int index, u16 lot) { if (indexType != LUA_TUSERDATA) { LOG_LUA_LINE("smlua_to_cobject received improper type '%s'", lua_typename(L, indexType)); gSmLuaConvertSuccess = false; - return 0; + return NULL; } CObject *cobject = luaL_checkudata(L, index, "CObject"); @@ -179,7 +179,7 @@ void* smlua_to_cpointer(lua_State* L, int index, u16 lvt) { if (indexType != LUA_TUSERDATA) { LOG_LUA_LINE("smlua_to_cpointer received improper type '%s'", lua_typename(L, indexType)); gSmLuaConvertSuccess = false; - return 0; + return NULL; } CPointer *cpointer = luaL_checkudata(L, index, "CPointer");