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.

This commit is contained in:
Matthew Budd 2020-11-01 21:45:36 -05:00
parent 9f10a1fb20
commit 87b6368956
1 changed files with 17 additions and 7 deletions

View File

@ -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;
}