Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shim over lua differences #30

Merged
merged 13 commits into from
Apr 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,18 @@ jobs:
if: ${{ matrix.goos == 'windows' }}
run: |
rm ${{env.basename}}/lua/Connector.lua
cp lua/Connector.lua ${{env.basename}}/lua/x64
cp lua/x64/socket.dll ${{env.basename}}/lua/x64
cp lua/Connector.lua ${{env.basename}}/lua/
cp lua/x64/socket-windows-5-1.dll ${{env.basename}}/lua/x64
cp lua/x64/socket-windows-5-4.dll ${{env.basename}}/lua/x64
cp lua/x64/luasocket.LICENSE.txt ${{env.basename}}/lua/x64
cp lua/Connector.lua ${{env.basename}}/lua/x86
cp lua/x86/socket.dll ${{env.basename}}/lua/x86
cp lua/x86/socket-windows-5-1.dll ${{env.basename}}/lua/x86
cp lua/x86/luasocket.LICENSE.txt ${{env.basename}}/lua/x86

- name: Copy in lua socket.so dependencies for Linux
if: ${{ matrix.goos == 'linux' }}
run: |
cp lua/x64/socket-linux.so ${{env.basename}}/lua/socket.so
cp lua/x64/socket-linux-5-4.so ${{env.basename}}/lua/x64/socket-linux-5-4.so
cp lua/x64/socket-linux-5-1.so ${{env.basename}}/lua/x64/socket-linux-5-1.so

- if: ${{ matrix.goos == 'windows' }}
name: Build SNI
Expand Down Expand Up @@ -232,14 +233,15 @@ jobs:
run: |
mkdir ${{env.basename}}
mkdir ${{env.basename}}/lua
# mkdir ${{env.basename}}/lua/x64
mkdir ${{env.basename}}/lua/x64
# mkdir ${{env.basename}}/lua/x86
cp README.md ${{env.basename}}
cp LICENSE ${{env.basename}}
cp protos/sni/sni.proto ${{env.basename}}
cp cmd/sni/apps.yaml ${{env.basename}}
cp lua/Connector.lua ${{env.basename}}/lua
cp lua/x64/socket-linux.so ${{env.basename}}/lua/socket.so
cp lua/x64/socket-linux-5-1.so ${{env.basename}}/lua/x64/socket-linux-5-1.so
cp lua/x64/socket-linux-5-4.so ${{env.basename}}/lua/x64/socket-linux-5-4.so
echo -e "\n--\nlibappindicator, libindicator and libdbusmenu are licensed under LGPL, see" >> ${{env.basename}}/LICENSE
echo "https://launchpad.net/libappindicator/" >> ${{env.basename}}/LICENSE
echo "https://launchpad.net/libindicator/" >> ${{env.basename}}/LICENSE
Expand Down
42 changes: 40 additions & 2 deletions lua/Connector.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
-- original file found in a GPLv3 code repository, unclear if this is the intended license nor who the authors are
-- SNI modifications by Berserker, jsd1982; modifications licensed under MIT License
-- version 3 changes Read response from JSON to HEX
-- lua 5.1/5.4 shim by zig; modifications licensed under MIT and WTFPL

function get_lua_version()
local major, minor = _VERSION:match("Lua (%d+)%.(%d+)")
assert(tonumber(major) == 5)
if tonumber(minor) >= 4 then
JamesDunne marked this conversation as resolved.
Show resolved Hide resolved
return "5-4"
end
return "5-1"
end

if not event then
is_snes9x = true
Expand All @@ -19,7 +29,7 @@ else
elseif emu.getluacore ~= nil then
current_engine = emu.getluacore();
end
if current_engine ~= nil and current_engine ~= "LuaInterface" then
if current_engine ~= nil and current_engine ~= "LuaInterface" and get_lua_version() ~= "5-4" then
print("Wrong Lua Core. Found " .. current_engine .. ", was expecting LuaInterface. ")
print("Please go to Config -> Customize -> Advanced and select Lua+LuaInterface.")
print("Once set, restart Bizhawk.")
Expand Down Expand Up @@ -65,7 +75,35 @@ function writebyte(addr, value, domain)
end
end

local socket = require("socket.core")
function get_os()
local the_os, ext, arch
if package.config:sub(1,1) == "\\" then
the_os, ext = "windows", "dll"
arch = os.getenv"PROCESSOR_ARCHITECTURE"
else
-- TODO: macos?
the_os, ext = "linux", "so"
arch = "x86_64" -- TODO: read ELF header from /proc/$PID/exe to get arch
end

if arch:find("64") ~= nil then
arch = "x64"
else
arch = "x86"
end

return the_os, ext, arch
end

function get_socket_path()
local the_os, ext, arch = get_os()
-- for some reason ./ isn't working, so use a horrible hack to get the pwd
local pwd = (io.popen and io.popen("cd"):read'*l') or "."
return pwd .. "/" .. arch .. "/socket-" .. the_os .. "-" .. get_lua_version() .. "." .. ext
end
local socket_path = get_socket_path()
print("loading " .. socket_path)
local socket = assert(package.loadlib(socket_path, "luaopen_socket_core"))()

local connection
local host = os.getenv("SNI_LUABRIDGE_LISTEN_HOST") or '127.0.0.1'
Expand Down
File renamed without changes.
Binary file added lua/x64/socket-linux-5-4.so
Binary file not shown.
File renamed without changes.
Binary file added lua/x64/socket-windows-5-4.dll
Binary file not shown.
File renamed without changes.