Skip to content

Commit

Permalink
Make Lua self-initializing
Browse files Browse the repository at this point in the history
  • Loading branch information
wheremyfoodat committed Sep 17, 2023
1 parent 7936a87 commit 4734e0b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ Emulator::Emulator()
}
}

lua.initialize();
reset(ReloadOption::NoReload);
}

Expand Down
13 changes: 13 additions & 0 deletions src/lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 4734e0b

Please sign in to comment.