From b39e3c727610cd58361ee784de874fc8bd20367a Mon Sep 17 00:00:00 2001 From: romoney5 Date: Mon, 8 Jun 2026 17:45:28 -0400 Subject: [PATCH] Print a warning when archiving an invalid Lua value --- src/lua_script.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lua_script.c b/src/lua_script.c index 2649a57c7..4e1cfc995 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -713,9 +713,12 @@ static UINT8 GetUserdataArchType(int index) static UINT8 ArchiveValue(UINT8 **p, int TABLESINDEX, int myindex) { + int type = lua_type(gL, myindex); + if (myindex < 0) myindex = lua_gettop(gL)+1+myindex; - switch (lua_type(gL, myindex)) + + switch (type) { case LUA_TNONE: case LUA_TNIL: @@ -725,8 +728,12 @@ static UINT8 ArchiveValue(UINT8 **p, int TABLESINDEX, int myindex) case LUA_TLIGHTUSERDATA: case LUA_TTHREAD: case LUA_TFUNCTION: + { + const char *typestr = (type == LUA_TLIGHTUSERDATA ? "light userdata" : (type == LUA_TTHREAD ? "thread" : (type == LUA_TFUNCTION ? "function" : "??"))); + CONS_Alert(CONS_ERROR, M_GetText("Archived an invalid value! (%s)\n"), typestr); WRITEUINT8(*p, ARCH_NULL); return 2; + } case LUA_TBOOLEAN: WRITEUINT8(*p, ARCH_BOOLEAN); WRITEUINT8(*p, lua_toboolean(gL, myindex));