Merge pull request #699 from TheRealQuantam/luafixes2

Multiple Lua Implementation Fixes
This commit is contained in:
thor2016 2024-02-04 09:07:23 -05:00 committed by GitHub
commit 5495c7eddc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 22 additions and 18 deletions

View File

@ -663,13 +663,6 @@ static int emu_loadrom(lua_State *L)
extern void LoadRecentRom(int slot); extern void LoadRecentRom(int slot);
LoadRecentRom(0); LoadRecentRom(0);
} }
if ( GameInfo )
{
//printf("Currently Loaded ROM: '%s'\n", GameInfo->filename );
lua_pushstring(L, GameInfo->filename);
return 1;
}
return 0;
#elif defined(__QT_DRIVER__) #elif defined(__QT_DRIVER__)
const char *nameo2 = luaL_checkstring(L,1); const char *nameo2 = luaL_checkstring(L,1);
std::string nameo; std::string nameo;
@ -685,15 +678,17 @@ static int emu_loadrom(lua_State *L)
// //printf("Failed to Load ROM: '%s'\n", nameo ); // //printf("Failed to Load ROM: '%s'\n", nameo );
// reloadLastGame(); // reloadLastGame();
//} //}
#endif
#if defined(__WIN_DRIVER__) || defined(__QT_DRIVER__)
if ( GameInfo ) if ( GameInfo )
{ {
//printf("Currently Loaded ROM: '%s'\n", GameInfo->filename ); //printf("Currently Loaded ROM: '%s'\n", GameInfo->filename );
lua_pushstring(L, GameInfo->filename); lua_pushstring(L, GameInfo->filename);
return 1; return 1;
} else {
return 0;
} }
#endif #endif
return 0; return 0;
} }
@ -1507,12 +1502,18 @@ static int rom_getfilename(lua_State *L) {
static int rom_gethash(lua_State *L) { static int rom_gethash(lua_State *L) {
const char *type = luaL_checkstring(L, 1); const char *type = luaL_checkstring(L, 1);
if (GameInfo != nullptr)
{
MD5DATA md5hash = GameInfo->MD5; MD5DATA md5hash = GameInfo->MD5;
if (!type) lua_pushstring(L, ""); if (!type) lua_pushstring(L, "");
else if (!stricmp(type, "md5")) lua_pushstring(L, md5_asciistr(md5hash)); else if (!stricmp(type, "md5")) lua_pushstring(L, md5_asciistr(md5hash));
else if (!stricmp(type, "base64")) lua_pushstring(L, BytesToString(md5hash.data, MD5DATA::size).c_str()); else if (!stricmp(type, "base64")) lua_pushstring(L, BytesToString(md5hash.data, MD5DATA::size).c_str());
else lua_pushstring(L, ""); else lua_pushstring(L, "");
}
else
lua_pushnil(L);
return 1; return 1;
} }
@ -2077,7 +2078,7 @@ static int memory_setregister(lua_State *L)
} }
// Forces a stack trace and returns the string // Forces a stack trace and returns the string
static const char *CallLuaTraceback(lua_State *L) { static const char *CallLuaTraceback(lua_State *L, int msgDepth = -1) {
lua_getfield(L, LUA_GLOBALSINDEX, "debug"); lua_getfield(L, LUA_GLOBALSINDEX, "debug");
if (!lua_istable(L, -1)) { if (!lua_istable(L, -1)) {
lua_pop(L, 1); lua_pop(L, 1);
@ -2090,20 +2091,23 @@ static const char *CallLuaTraceback(lua_State *L) {
return ""; return "";
} }
lua_pushvalue(L, 1); if (msgDepth < 0)
msgDepth -= 2; // We pushed 2 onto the stack
lua_pushvalue(L, msgDepth);
lua_call(L, 1, 1); lua_call(L, 1, 1);
return lua_tostring(L, -1); return lua_tostring(L, -1);
} }
void HandleCallbackError(lua_State* L, bool stop) void HandleCallbackError(lua_State* L, bool stop, int msgDepth = -1)
{ {
//if(L->errfunc || L->errorJmp) //if(L->errfunc || L->errorJmp)
// luaL_error(L, "%s", lua_tostring(L,-1)); // luaL_error(L, "%s", lua_tostring(L,-1));
//else //else
{ {
const char *trace = CallLuaTraceback(L); const char *trace = CallLuaTraceback(L, msgDepth);
lua_pushnil(L); lua_pushnil(L);
lua_setfield(L, LUA_REGISTRYINDEX, guiCallbackTable); lua_setfield(L, LUA_REGISTRYINDEX, guiCallbackTable);