2021-04-07 17:27:15 +00:00
|
|
|
sent = {}
|
2021-04-07 13:55:15 +00:00
|
|
|
sent.register = function (cfg)
|
|
|
|
if cfg.name == nil then
|
|
|
|
error("sent.register: needs name")
|
|
|
|
end
|
|
|
|
if cfg.cls == nil then
|
|
|
|
error("sent.register: needs cls")
|
|
|
|
end
|
|
|
|
local name = cfg.name
|
|
|
|
local cls = cfg.cls
|
|
|
|
local components = cfg.components or {}
|
|
|
|
|
2021-04-05 22:09:31 +00:00
|
|
|
if cls.__sent_class_id ~= nil then
|
2021-04-07 13:55:15 +00:00
|
|
|
error(string.format("sent.register: %s already registered", name))
|
2021-04-05 22:09:31 +00:00
|
|
|
return
|
|
|
|
end
|
2021-04-07 13:55:15 +00:00
|
|
|
|
|
|
|
-- Recreate config when calling native function, to ensure no metatable
|
|
|
|
-- fuckery.
|
|
|
|
local sent_class_id = __sent_register({
|
|
|
|
name = name,
|
|
|
|
cls = cls,
|
|
|
|
components = components,
|
|
|
|
})
|
|
|
|
|
2021-04-05 22:09:31 +00:00
|
|
|
cls.__sent_class_id = sent_class_id
|
|
|
|
cls.new = function(...)
|
|
|
|
local arg = {...}
|
2021-04-08 22:39:11 +00:00
|
|
|
|
|
|
|
-- Make object table, instantiate with runtime.
|
|
|
|
local table = {}
|
|
|
|
local sent_id = __sent_new(table, sent_class_id)
|
|
|
|
table.__sent_id = sent_id
|
|
|
|
|
2021-04-08 22:49:26 +00:00
|
|
|
-- Make 'tick' trampoline, used by runtime to do fast call into ticker
|
|
|
|
-- without bind/argument push.
|
|
|
|
table.__sent_tick = function()
|
|
|
|
if table.tick ~= nil then
|
|
|
|
table:tick()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-08 22:39:11 +00:00
|
|
|
-- Configure components dispatcher.
|
|
|
|
table.components = {}
|
|
|
|
table.components.__sent_id = sent_id
|
|
|
|
local components_meta = {}
|
|
|
|
components_meta.__index = function(t, k)
|
|
|
|
return __sent_components_index(t, k)
|
|
|
|
end
|
|
|
|
components_meta.__newindex = function(t, k, v)
|
|
|
|
return __sent_components_newindex(t, k, v)
|
2021-04-05 22:09:31 +00:00
|
|
|
end
|
2021-04-08 22:39:11 +00:00
|
|
|
setmetatable(table.components, components_meta)
|
|
|
|
|
|
|
|
-- Make table deref via table to class.
|
|
|
|
local metatable = {}
|
|
|
|
metatable.__index = cls
|
|
|
|
setmetatable(table, metatable)
|
|
|
|
|
|
|
|
-- Call initializer, if present.
|
|
|
|
if table.init ~= nil then
|
|
|
|
table:init(unpack(arg))
|
|
|
|
end
|
|
|
|
|
|
|
|
return table
|
2021-04-05 22:09:31 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-07 17:27:15 +00:00
|
|
|
require("//engine/scene.lua")
|