Skip to content

Commit

Permalink
fix: lua 5.1 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
RodrigoDornelles committed Jul 31, 2024
1 parent c439576 commit 3338a68
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 15 deletions.
5 changes: 2 additions & 3 deletions examples/launcher/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ local function loop(std, game)
next_state(game, 6)
elseif game._state == 6 then
halt_state(game)(function()
game._app = load(game._source)
game._app = game._app()
game._app = std.game.load(game._source)
game._app.callbacks.init(std, game)
game._source = ''
next_state(game, 7)
Expand Down Expand Up @@ -240,7 +239,7 @@ local P = {
version='1.0.0'
},
config={
require='http random math csv'
require='http random math csv load'
},
callbacks={
init=init,
Expand Down
1 change: 1 addition & 0 deletions src/engine/core/ginga/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ local function install(evt, gamefile)
:package('@draw', engine_draw, ginga)
:package('@draw_fps', engine_draw_fps)
:package('@draw_poly', engine_draw_poly, polygons)
:package('load', zeebo_module.load)
:package('csv', engine_csv)
:package('math', engine_math.clib)
:package('random', engine_math.clib_random)
Expand Down
1 change: 1 addition & 0 deletions src/engine/core/html5/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ local function browser_init(width, height)
:package('@game', engine_game)
:package('@math', engine_math)
:package('@color', engine_color)
:package('load', zeebo_module.load)
:package('math', engine_math.clib)
:package('random', engine_math.clib_random)
:package('http', engine_http, browser_protocol_http)
Expand Down
1 change: 1 addition & 0 deletions src/engine/core/love/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function love.load(args)
:package('@color', engine_color)
:package('@draw_fps', engine_draw_fps)
:package('@draw_poly', engine_draw_poly, polygons)
:package('load', zeebo_module.load)
:package('math', engine_math.clib)
:package('random', engine_math.clib_random)
:package('http', engine_http, protocol_curl)
Expand Down
1 change: 1 addition & 0 deletions src/engine/core/nintendo_wii/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function love.load(args)
:package('@loop', engine_loop)
:package('@color', engine_color)
:package('@draw_poly', engine_draw_poly, polygons)
:package('load', zeebo_module.load)
:package('math', engine_math.clib)
:package('random', engine_math.clib_random)
:run()
Expand Down
38 changes: 27 additions & 11 deletions src/lib/engine/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,30 @@ local zeebo_pipeline = require('src/lib/util/pipeline')
--! @li https://love2d.org/wiki/love.filesystem.getSource
local function loadgame(game_file)
local cwd = '.'
local application = nil
local application = type(game_file) == 'function' and game_file
local game_title = game_file and game_file:gsub('%.lua$', '') or 'game'

if love and love.filesystem and love.filesystem.getSource then
cwd = love.filesystem.getSource()
end
if loadfile then
application = loadfile(cwd..'/'..game_title..'.lua')
end
if not application and pcall and require then
local ok, app = pcall(require, game_title)


if not application and game_file and game_file:find('\n') then
local ok, app = pcall(load, game_file)
if not ok then
ok, app = pcall(loadstring, game_file)
end
application = ok and app
else
if love and love.filesystem and love.filesystem.getSource then
cwd = love.filesystem.getSource()
end
if not application then
application = loadfile(cwd..'/'..game_title..'.lua')
end
if not application then
local ok, app = pcall(require, game_title)
application = ok and app
end
end

if type(application) == 'function' then
while application and type(application) == 'function' do
application = application()
end

Expand Down Expand Up @@ -114,7 +123,14 @@ local function require(std, game, application)
return self
end

local function install(std, game, application, exit_func)
std.game = std.game or {}
std.game.load = loadgame
return {load=loadgame}
end

local P = {
load={install=install},
loadgame = loadgame,
require = require
}
Expand Down
19 changes: 18 additions & 1 deletion src/lib/protocol/http_ginga.lua
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ local function http_handler(self)
local protocol, location = self.url:match('(%w*)://?(.*)')
local url, uri = (location or self.url):match('^([^/]+)(.*)$')
local host, port_str = url:match("^(.-):?(%d*)$")
local port = tonumber(port_str and #port_str > 0 or 80)
local port = tonumber(port_str and #port_str > 0 and port_str or 80)

self.p_url = url
self.p_uri = uri or '/'
Expand Down Expand Up @@ -191,6 +191,7 @@ end
local function context_pull(evt, contexts)
local host = evt.host
local connection = evt.connection
local index = host and contexts.by_host[host] and #contexts.by_host[host]

if evt.type == 'connect' and host and contexts.by_host[host] then
local index = #contexts.by_host[host]
Expand All @@ -204,6 +205,22 @@ local function context_pull(evt, contexts)
contexts.by_connection[connection] = self
contexts.by_host[host][index] = nil
return self
elseif evt.type == 'disconnect' then
local self = {speed=''}
if host and index and contexts.by_host[host][index] then
self = contexts.by_host[host][index]
contexts.by_host[host][index] = nil
end
if connection and contexts.by_connection[connection] then
self = contexts.by_connection[connection]
contexts.by_connection[connection] = nil
end
if evt.error then
self.evt = {type = 'error', error = evt.error}
else
self.evt = evt
end
return self
elseif connection and contexts.by_connection[connection] then
local self = contexts.by_connection[connection]
if evt.error then
Expand Down

0 comments on commit 3338a68

Please sign in to comment.