4--! @brief search by
game in filesystem / lua modules
7 if type(game_file) ==
'table' then
12 local
application = type(game_file) ==
'function' and game_file
13 local game_title = game_file and game_file:gsub(
'%.lua$',
'') or '
game'
16 if not
application and game_file and game_file:find('\n') then
17 local
ok, app = pcall(
load, game_file)
19 ok, app = pcall(loadstring, game_file)
23 if love and love.filesystem and love.filesystem.getSource then
24 cwd = love.filesystem.getSource()
30 local
ok, app = pcall(
require, game_title)
35 local app_file = io.open(game_file)
37 local app_src = app_file:read('*a')
38 local
ok, app = pcall(
load, app_src)
40 ok, app = pcall(loadstring, app_src)
54local function
register(self, register_func)
55 local listener_func = function(event_name)
56 local filtered_events = {}
60 while index <= #self.event
do
61 local
event = self.event[index][event_name]
63 filtered_events[#filtered_events + 1] =
event
69 return function(a, b, c, d, e, f)
71 while index <= #filtered_events
do
72 filtered_events[index](self.std, self.game, self.application, a, b, c, d, e, f)
78 self.pipeline[#self.pipeline + 1] = function()
79 register_func(listener_func)
85local function
package(self, module_name, module, custom)
86 local system = module_name:sub(1, 1) ==
'@'
87 local name = system and module_name:sub(2) or module_name
90 self.stdlib_required[name] = true
93 self.pipeline[
#self.pipeline + 1] = function ()
94 if not self.list_exist(name) then
return end
95 if not system and not self.lib_required[name] then
return end
97 local try_install = function()
100 self.
event[
#self.event + 1] = m.event
104 if not pcall(try_install) then
return end
107 self.stdlib_installed[name] =
true
109 self.lib_installed[name] =
true
118 local next_library = application_require:gmatch(
'%S+')
133 stdlib_required = {},
134 stdlib_installed = {},
137 pipe = zeebo_pipeline.pipe
140 self.list_exist = function (name)
141 return self.lib_optional[name] or self.lib_required[name] or self.stdlib_required[name]
143 self.list_append = function (name)
144 if not self.list_exist(name) then
145 self.list[#self.list + 1] = name
148 self.run = function()
150 zeebo_pipeline.run(self)
151 while index <= #self.list do
152 local name = self.list[index]
153 if self.stdlib_required[name] and not self.stdlib_installed[name] then
154 error('system library not loaded: '..name)
156 if self.lib_required[name] and not self.lib_installed[name] then
157 error('library not loaded: '..name)
164 local lib = next_library()
166 local name, optional = lib:match('([%w%.]+)([?]?)')
167 self.list_append(name)
168 if optional and #optional > 0 then
169 self.lib_optional[name] = true
171 self.lib_required[name] = true
179local function install(std, game, application, exit_func)
180 std.game = std.game or {}
181 std.game.load = loadgame
182 return {load=loadgame}
186 load={install=install},
local function require(std, game, application)
local function loadgame(game_file)
safe load game
local function package(self, module_name, module, custom)
local function register(self, register_func)
local function install(std, game, application, exit_func)