2019-03-10 00:14:30 +02:00
|
|
|
local Event = require 'utils.event_core'
|
|
|
|
local Token = require 'utils.token'
|
2018-09-19 06:51:25 +02:00
|
|
|
|
|
|
|
local Global = {}
|
|
|
|
|
|
|
|
function Global.register(tbl, callback)
|
2019-03-10 00:14:30 +02:00
|
|
|
if _LIFECYCLE ~= _STAGE.control then
|
|
|
|
error('can only be called during the control stage', 2)
|
|
|
|
end
|
2018-09-19 06:51:25 +02:00
|
|
|
local token = Token.register_global(tbl)
|
2019-03-10 00:14:30 +02:00
|
|
|
|
|
|
|
Event.on_load(
|
|
|
|
function()
|
|
|
|
callback(Token.get_global(token))
|
|
|
|
end
|
|
|
|
)
|
2019-10-26 13:10:56 +02:00
|
|
|
|
|
|
|
return token
|
2018-09-19 06:51:25 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function Global.register_init(tbl, init_handler, callback)
|
2019-03-10 00:14:30 +02:00
|
|
|
if _LIFECYCLE ~= _STAGE.control then
|
|
|
|
error('can only be called during the control stage', 2)
|
|
|
|
end
|
2018-09-19 06:51:25 +02:00
|
|
|
local token = Token.register_global(tbl)
|
|
|
|
|
2019-03-10 00:14:30 +02:00
|
|
|
Event.on_init(
|
|
|
|
function()
|
|
|
|
init_handler(tbl)
|
|
|
|
callback(tbl)
|
|
|
|
end
|
|
|
|
)
|
2018-09-19 06:51:25 +02:00
|
|
|
|
2019-03-10 00:14:30 +02:00
|
|
|
Event.on_load(
|
|
|
|
function()
|
|
|
|
callback(Token.get_global(token))
|
2018-09-19 06:51:25 +02:00
|
|
|
end
|
2019-03-10 00:14:30 +02:00
|
|
|
)
|
2019-10-26 13:10:56 +02:00
|
|
|
|
|
|
|
return token
|
2019-03-10 00:14:30 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if _DEBUG then
|
|
|
|
local concat = table.concat
|
2018-09-19 06:51:25 +02:00
|
|
|
|
2019-03-10 00:14:30 +02:00
|
|
|
local names = {}
|
|
|
|
Global.names = names
|
|
|
|
|
|
|
|
function Global.register(tbl, callback)
|
|
|
|
local filepath = debug.getinfo(2, 'S').source:match('^.+/currently%-playing/(.+)$'):sub(1, -5)
|
|
|
|
local token = Token.register_global(tbl)
|
|
|
|
|
|
|
|
names[token] = concat {token, ' - ', filepath}
|
|
|
|
|
|
|
|
Event.on_load(
|
|
|
|
function()
|
|
|
|
callback(Token.get_global(token))
|
|
|
|
end
|
|
|
|
)
|
2019-10-26 13:10:56 +02:00
|
|
|
|
|
|
|
return token
|
2018-09-19 06:51:25 +02:00
|
|
|
end
|
|
|
|
|
2019-03-10 00:14:30 +02:00
|
|
|
function Global.register_init(tbl, init_handler, callback)
|
|
|
|
local filepath = debug.getinfo(2, 'S').source:match('^.+/currently%-playing/(.+)$'):sub(1, -5)
|
|
|
|
local token = Token.register_global(tbl)
|
|
|
|
|
|
|
|
names[token] = concat {token, ' - ', filepath}
|
|
|
|
|
|
|
|
Event.on_init(
|
|
|
|
function()
|
|
|
|
init_handler(tbl)
|
|
|
|
callback(tbl)
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
|
|
|
Event.on_load(
|
|
|
|
function()
|
|
|
|
callback(Token.get_global(token))
|
|
|
|
end
|
|
|
|
)
|
2019-10-26 13:10:56 +02:00
|
|
|
|
|
|
|
return token
|
2018-09-19 06:51:25 +02:00
|
|
|
end
|
2019-03-10 00:14:30 +02:00
|
|
|
end
|
2018-09-19 06:51:25 +02:00
|
|
|
|
|
|
|
return Global
|