From 5c29bdbd8d06e3c7a810152518c964a35478d3f5 Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Sat, 31 Oct 2020 16:25:29 -0400 Subject: [PATCH] Lua scripting pathing improvements for Linux/MacOS. Use realpath when possible to always have a absolute path for scripts and roms internally. --- src/drivers/Qt/fceuWrapper.cpp | 3 ++- src/lua-engine.cpp | 8 +------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/drivers/Qt/fceuWrapper.cpp b/src/drivers/Qt/fceuWrapper.cpp index d823ae04..4ab56df4 100644 --- a/src/drivers/Qt/fceuWrapper.cpp +++ b/src/drivers/Qt/fceuWrapper.cpp @@ -753,7 +753,8 @@ int fceuWrapperInit( int argc, char *argv[] ) g_config->setOption("SDL.LuaScript", ""); if (s != "") { -#ifdef __linux +#if defined(__linux) || defined(__APPLE__) + // Resolve absolute path to file char fullpath[2048]; if ( realpath( s.c_str(), fullpath ) != NULL ) diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp index 4b27d8ff..e0316e2a 100644 --- a/src/lua-engine.cpp +++ b/src/lua-engine.cpp @@ -618,16 +618,10 @@ static int emu_loadrom(lua_State *L) const char *nameo2 = luaL_checkstring(L,1); char nameo[2048]; - if ( nameo2[0] == '/' ) + if ( realpath( nameo2, nameo ) == NULL ) { strncpy(nameo, nameo2, sizeof(nameo)); } - else - { - char cwd[1024]; - getcwd( cwd, sizeof(cwd) ); - snprintf( nameo, sizeof(nameo), "%s/%s", cwd, nameo2 ); - } //printf("Load ROM: '%s'\n", nameo ); if (!LoadGame(nameo, true)) {