From ec72160f395671a6dbc665b2e657219754151947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20Peri=C4=87?= Date: Wed, 21 Oct 2020 22:05:26 +0200 Subject: [PATCH] Added support for loading ROM files from Lua script on Linux --- src/drivers/Qt/fceuWrapper.cpp | 6 ++++++ src/drivers/sdl/sdl.cpp | 6 ++++++ src/lua-engine.cpp | 11 +++++++++++ 3 files changed, 23 insertions(+) diff --git a/src/drivers/Qt/fceuWrapper.cpp b/src/drivers/Qt/fceuWrapper.cpp index ddc1b0e2..cdc27dd7 100644 --- a/src/drivers/Qt/fceuWrapper.cpp +++ b/src/drivers/Qt/fceuWrapper.cpp @@ -206,6 +206,12 @@ DriverKill() inited=0; } +int reloadLastGame() { + std::string lastRom; + g_config->getOption(std::string("SDL.LastOpenFile"), &lastRom); + return LoadGame(lastRom.c_str()); +} + /** * Loads a game, given a full path/filename. The driver code must be * initialized after the game is loaded, because the emulator code diff --git a/src/drivers/sdl/sdl.cpp b/src/drivers/sdl/sdl.cpp index 25f7f0aa..ce9482fc 100644 --- a/src/drivers/sdl/sdl.cpp +++ b/src/drivers/sdl/sdl.cpp @@ -189,6 +189,12 @@ static void ShowUsage(char *prog) } +int reloadLastGame() { + std::string lastRom; + g_config->getOption(std::string("SDL.LastOpenFile"), &lastRom); + return LoadGame(lastRom.c_str()); +} + /** * Loads a game, given a full path/filename. The driver code must be * initialized after the game is loaded, because the emulator code diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp index 42344162..74ded2ab 100644 --- a/src/lua-engine.cpp +++ b/src/lua-engine.cpp @@ -545,6 +545,17 @@ static int emu_loadrom(lua_State *L) { } else { return 1; } +#else + const char *nameo2 = luaL_checkstring(L,1); + char nameo[2048]; + strncpy(nameo, nameo2, sizeof(nameo)); + if(!FCEUI_LoadGame(nameo, 0, true)) { + extern void reloadLastGame(); + reloadLastGame(); + return 0; + } else { + return 1; + } #endif return 1; }