diff --git a/src/emulator.cpp b/src/emulator.cpp index fab95d491..ba9b06237 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 ae491eb99..bcaac3ab5 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