From 87b6368956e8b4e403a5a7da5bd11c2560cf4c7e Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Sun, 1 Nov 2020 21:45:36 -0500 Subject: [PATCH] Changed the lua emu.loadrom function to have a string return value containing the path to the currently loaded ROM. The old function had no return value. This return value allows for the user to determine what game was loaded since the function behavior is to try to reload the last known ROM if the passed argument cannot be loaded. --- src/lua-engine.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp index fca51711..2f624c06 100644 --- a/src/lua-engine.cpp +++ b/src/lua-engine.cpp @@ -600,7 +600,7 @@ static int emu_loadrom(lua_State *L) const char* str = lua_tostring(L,1); //special case: reload rom - if(!str) { + if (!str) { ReloadRom(); return 0; } @@ -611,10 +611,14 @@ static int emu_loadrom(lua_State *L) if (!ALoad(nameo)) { extern void LoadRecentRom(int slot); LoadRecentRom(0); - return 0; - } else { + } + if ( GameInfo ) + { + //printf("Currently Loaded ROM: '%s'\n", GameInfo->filename ); + lua_pushstring(L, GameInfo->filename); return 1; } + return 0; #else const char *nameo2 = luaL_checkstring(L,1); char nameo[2048]; @@ -623,16 +627,22 @@ static int emu_loadrom(lua_State *L) { strncpy(nameo, nameo2, sizeof(nameo)); } - //printf("Load ROM: '%s'\n", nameo ); + //printf("Attempting to Load ROM: '%s'\n", nameo ); if (!LoadGame(nameo, true)) { + //printf("Failed to Load ROM: '%s'\n", nameo ); reloadLastGame(); - return 0; - } else { + } + if ( GameInfo ) + { + //printf("Currently Loaded ROM: '%s'\n", GameInfo->filename ); + lua_pushstring(L, GameInfo->filename); return 1; + } else { + return 0; } #endif - return 1; + return 0; }