From 44f45d6d2835e3a82336d38229e181c7946f8548 Mon Sep 17 00:00:00 2001 From: Latapostrophe Date: Thu, 12 Mar 2020 16:03:12 +0100 Subject: [PATCH] Fix Lua crashes when loading without addons --- src/g_game.c | 6 ++++++ src/lua_script.c | 2 +- src/lua_script.h | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/g_game.c b/src/g_game.c index 352a6084..4fce4db8 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -45,6 +45,7 @@ #include "dehacked.h" // get_number (for ghost thok) #include "lua_script.h" // LUA_ArchiveDemo and LUA_UnArchiveDemo #include "lua_hook.h" +#include "lua_libs.h" // gL (Lua state) #include "b_bot.h" #include "m_cond.h" // condition sets #include "md5.h" // demo checksums @@ -7538,7 +7539,12 @@ void G_DoPlayDemo(char *defdemoname) // so this is where we are to read our lua variables (if possible!) #ifdef HAVE_BLUA if (demoflags & DF_LUAVARS) // again, used for compability, lua shit will be saved to replays regardless of if it's even been loaded + { + if (!gL) // No Lua state! ...I guess we'll just start one... + LUA_ClearState(); + LUA_UnArchiveDemo(); + } #endif splitscreen = 0; diff --git a/src/lua_script.c b/src/lua_script.c index aa6a5652..6961f2e9 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -112,7 +112,7 @@ static int noglobals(lua_State *L) // Clear and create a new Lua state, laddo! // There's SCRIPTIN to be had! -static void LUA_ClearState(void) +void LUA_ClearState(void) { lua_State *L; int i; diff --git a/src/lua_script.h b/src/lua_script.h index dffd39c4..b3ca16bc 100644 --- a/src/lua_script.h +++ b/src/lua_script.h @@ -38,6 +38,8 @@ void LUA_ClearExtVars(void); #endif +void LUA_ClearState(void); + void LUA_LoadLump(UINT16 wad, UINT16 lump); #ifdef LUA_ALLOW_BYTECODE void LUA_DumpFile(const char *filename);