Skip to content

Instantly share code, notes, and snippets.

@jagt
Created December 18, 2017 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jagt/6aa17d9478cec960c62f86356a7ab41f to your computer and use it in GitHub Desktop.
Save jagt/6aa17d9478cec960c62f86356a7ab41f to your computer and use it in GitHub Desktop.
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