2018-06-09 11:43:37 +01:00
|
|
|
local Event = require 'utils.event'
|
2018-11-25 20:07:03 -05:00
|
|
|
local Token = require 'utils.token'
|
2018-06-09 11:43:37 +01:00
|
|
|
|
2018-07-04 16:22:26 +01:00
|
|
|
local Global = {}
|
2018-06-09 11:43:37 +01:00
|
|
|
|
2018-06-17 11:39:55 +01:00
|
|
|
local load_data = {}
|
|
|
|
local init_data = {}
|
2018-06-09 11:43:37 +01:00
|
|
|
|
|
|
|
function Global.register(tbl, callback)
|
|
|
|
local token = Token.register_global(tbl)
|
2018-09-22 23:25:13 +01:00
|
|
|
table.insert(load_data, {callback = callback, token = token})
|
2018-06-17 11:39:55 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function Global.register_init(tbl, init_handler, callback)
|
|
|
|
local token = Token.register_global(tbl)
|
2018-09-22 23:25:13 +01:00
|
|
|
table.insert(load_data, {callback = callback, token = token})
|
2018-06-17 11:39:55 +01:00
|
|
|
|
|
|
|
table.insert(init_data, {token = token, init_handler = init_handler, callback = callback})
|
2018-06-09 11:43:37 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
Event.on_load(
|
|
|
|
function()
|
2018-06-17 11:39:55 +01:00
|
|
|
for _, d in ipairs(load_data) do
|
|
|
|
local tbl = Token.get_global(d.token)
|
|
|
|
d.callback(tbl)
|
|
|
|
end
|
|
|
|
|
|
|
|
load_data = nil
|
|
|
|
init_data = nil
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
|
|
|
Event.on_init(
|
|
|
|
function()
|
|
|
|
for _, d in ipairs(init_data) do
|
2018-06-09 11:43:37 +01:00
|
|
|
local tbl = Token.get_global(d.token)
|
2018-06-17 11:39:55 +01:00
|
|
|
d.init_handler(tbl)
|
2018-06-09 11:43:37 +01:00
|
|
|
d.callback(tbl)
|
|
|
|
end
|
|
|
|
|
2018-06-17 11:39:55 +01:00
|
|
|
load_data = nil
|
|
|
|
init_data = nil
|
2018-06-09 11:43:37 +01:00
|
|
|
end
|
|
|
|
)
|
|
|
|
|
|
|
|
return Global
|