mirror of
https://github.com/vrld/hump.git
synced 2024-11-23 12:24:19 +00:00
Localize function registry to Gamestate.switch().
This commit is contained in:
parent
b3c329a1e8
commit
87b82750ff
@ -60,10 +60,6 @@ function GS.current()
|
||||
return stack[#stack]
|
||||
end
|
||||
|
||||
-- holds all defined love callbacks after GS.registerEvents is called
|
||||
-- returns empty function on undefined callback
|
||||
local registry = setmetatable({}, {__index = function() return __NULL__ end})
|
||||
|
||||
local all_callbacks = {
|
||||
'update', 'draw', 'focus', 'keypressed', 'keyreleased',
|
||||
'mousepressed', 'mousereleased', 'joystickpressed',
|
||||
@ -71,17 +67,20 @@ local all_callbacks = {
|
||||
}
|
||||
|
||||
function GS.registerEvents(callbacks)
|
||||
local registry = {}
|
||||
callbacks = callbacks or all_callbacks
|
||||
for _, f in ipairs(callbacks) do
|
||||
registry[f] = love[f]
|
||||
love[f] = function(...) return GS[f](...) end
|
||||
registry[f] = love[f] or __NULL__
|
||||
love[f] = function(...)
|
||||
registry[f](...)
|
||||
return GS[f](...)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- forward any undefined functions
|
||||
setmetatable(GS, {__index = function(_, func)
|
||||
return function(...)
|
||||
registry[func](...)
|
||||
return (stack[#stack][func] or __NULL__)(stack[#stack], ...)
|
||||
end
|
||||
end})
|
||||
|
Loading…
Reference in New Issue
Block a user