local ecs = require 'honey.ecs.ecs' local node = require 'honey.ecs.node' local module = {} setmetatable(module, {__index=_G}) setfenv(1, module) -- helper function for retrieving script functions getFunction = function(script) local f = require(script.script) if script.func then return f[script.func] else return f end end --===== dispatch messages to handlers =====-- dispatch = function(db, msg, data) local query = db:queryComponent(msg) for id, handler in pairs(query) do local f = getFunction(handler) f(entities, id, data) end end --===== script system =====-- local script = ecs.System("script", function(db, dt, params) local entities = db:queryComponent("script") for id, script in pairs(entities) do local f = getFunction(script) f(db, id, dt) end end) script:addDependencies(node.system) system = {script} return module