Skip to content

Commit

Permalink
Fix #3616
Browse files Browse the repository at this point in the history
This had two issues. One, relative pathing with dlls is a no-go. Our hackery with changing cwd seems to confuse lua, and while it can find the dll, it fails to load as Windows (at least) does not consider cwd for loading up dlls it appears. Secondly, people using luasockets never actually loaded up the luasockets dll, rather we were bundling it ourselves. From history it seems this was due to our lua being compiled with CLR/.NET and that didn't play nice with exceptions? Doesn't seem to be an issue anymore, but we should probably still bundle luasockets for the time being given it used in many different projects which use the same script with multiple different emulators (thus our own sockets are simply not usable).
  • Loading branch information
CasualPokePlayer authored and vadosnaprimer committed May 2, 2023
1 parent 4079b96 commit 0516c2e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
Binary file added Assets/Lua/mime/core.dll
Binary file not shown.
Binary file added Assets/Lua/socket/core.dll
Binary file not shown.
15 changes: 13 additions & 2 deletions src/BizHawk.Client.EmuHawk/tools/Lua/LuaLibraries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,24 @@ void EnumerateLuaFunctions(string name, Type type, LuaLibraryBase instance)
}

_lua.RegisterFunction("print", this, typeof(LuaLibraries).GetMethod(nameof(Print)));

var packageTable = (LuaTable) _lua["package"];
var luaPath = PathEntries.LuaAbsolutePath();
if (OSTailoredCode.IsUnixHost)
{
// add %exe%/Lua to library resolution pathset (LUA_PATH)
// this is done already on windows, but not on linux it seems?
var packageTable = (LuaTable) _lua["package"];
var luaPath = PathEntries.LuaAbsolutePath();
packageTable["path"] = $"{luaPath}/?.lua;{luaPath}?/init.lua;{packageTable["path"]}";
// we need to modifiy the cpath so it looks at our lua dir too, and remove the relative pathing
// we do this on Windows too, but keep in mind Linux uses .so and Windows use .dll
// TODO: Does the relative pathing issue Windows has also affect Linux? I'd assume so...
packageTable["cpath"] = $"{luaPath}/?.so;{luaPath}/loadall.so;{packageTable["cpath"]}";
packageTable["cpath"] = ((string)packageTable["cpath"]).Replace(";./?.so", "");
}
else
{
packageTable["cpath"] = $"{luaPath}\\?.dll;{luaPath}\\loadall.dll;{packageTable["cpath"]}";
packageTable["cpath"] = ((string)packageTable["cpath"]).Replace(";.\\?.dll", "");
}

EmulationLuaLibrary.FrameAdvanceCallback = FrameAdvance;
Expand Down

0 comments on commit 0516c2e

Please sign in to comment.