Bug fix for issue #215. MacOS was not changing the current working directory to the lua script location when loading a lua script.

This commit is contained in:
Matthew Budd 2020-10-31 16:08:22 -04:00
parent ec875b9357
commit 0cca02e765
1 changed files with 15 additions and 4 deletions

View File

@ -7,6 +7,7 @@
#include <libgen.h>
#elif __APPLE__
#include <stdlib.h>
#include <unistd.h>
#include <libgen.h>
#include <mach-o/dyld.h>
#endif
@ -616,7 +617,18 @@ static int emu_loadrom(lua_State *L)
#else
const char *nameo2 = luaL_checkstring(L,1);
char nameo[2048];
strncpy(nameo, nameo2, sizeof(nameo));
if ( nameo2[0] == '/' )
{
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))
{
reloadLastGame();
@ -6183,7 +6195,8 @@ void FCEU_LuaFrameBoundary()
*
* Returns true on success, false on failure.
*/
int FCEU_LoadLuaCode(const char *filename, const char *arg) {
int FCEU_LoadLuaCode(const char *filename, const char *arg)
{
if (!DemandLua())
{
return 0;
@ -6195,13 +6208,11 @@ int FCEU_LoadLuaCode(const char *filename, const char *arg) {
luaScriptName = strdup(filename);
}
#if defined(WIN32) || defined(__linux)
std::string getfilepath = filename;
getfilepath = getfilepath.substr(0,getfilepath.find_last_of("/\\") + 1);
SetCurrentDir(getfilepath.c_str());
#endif
//stop any lua we might already have had running
FCEU_LuaStop();