Created
December 18, 2017 16:06
-
-
Save jagt/6aa17d9478cec960c62f86356a7ab41f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local delegates = {} | |
local function OnEvent(evt, cb) | |
local cb_dump = string.dump(cb) | |
delegates[evt] = cb_dump | |
end | |
-- declare callbacks | |
OnEvent('hit', function(evt) | |
damage(evt.source) | |
end) | |
-- create runtime | |
local rt_env = { | |
damage = function(id) | |
print('hitting on target:'..id) | |
end | |
} | |
local runtime = {} | |
for k, v in pairs(delegates) do | |
runtime[k] = load(v, k, 'b', rt_env) | |
end | |
-- dispatch | |
runtime['hit']{ source = 253 } | |
-- prints 'hitting on target: 253' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment