From 4734e0b5e35693d16984aede054d4e5b2f1864e3 Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Mon, 18 Sep 2023 00:40:11 +0300 Subject: [PATCH] Make Lua self-initializing --- src/emulator.cpp | 1 - src/lua.cpp | 13 +++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/emulator.cpp b/src/emulator.cpp index fab95d49..ba9b0623 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -82,7 +82,6 @@ Emulator::Emulator() } } - lua.initialize(); reset(ReloadOption::NoReload); } diff --git a/src/lua.cpp b/src/lua.cpp index ae491eb9..bcaac3ab 100644 --- a/src/lua.cpp +++ b/src/lua.cpp @@ -27,6 +27,19 @@ void LuaManager::close() { } void LuaManager::loadFile(const char* path) { + // Initialize Lua if it has not been initialized + if (!initialized) { + initialize(); + } + + // If init failed, don't execute + if (!initialized) { + printf("Lua initialization failed, file won't run\n"); + haveScript = false; + + return; + } + int status = luaL_loadfile(L, path); // load Lua script int ret = lua_pcall(L, 0, 0, 0); // tell Lua to run the script