mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-25 09:30:03 +00:00
Increment component id
This commit is contained in:
parent
21f71f803d
commit
c5daddd505
1 changed files with 7 additions and 1 deletions
|
@ -265,9 +265,9 @@ local topoRuntime = {
|
||||||
-- It should not be accessible through indexing into a component instance directly.
|
-- It should not be accessible through indexing into a component instance directly.
|
||||||
local DIAGNOSTIC_COMPONENT_MARKER = {}
|
local DIAGNOSTIC_COMPONENT_MARKER = {}
|
||||||
|
|
||||||
|
local nextId = 0
|
||||||
local function newComponent(name, defaultData)
|
local function newComponent(name, defaultData)
|
||||||
name = name or debug.info(2, "s") .. "@" .. debug.info(2, "l")
|
name = name or debug.info(2, "s") .. "@" .. debug.info(2, "l")
|
||||||
|
|
||||||
assert(
|
assert(
|
||||||
defaultData == nil or type(defaultData) == "table",
|
defaultData == nil or type(defaultData) == "table",
|
||||||
"if component default data is specified, it must be a table"
|
"if component default data is specified, it must be a table"
|
||||||
|
@ -320,6 +320,9 @@ local function newComponent(name, defaultData)
|
||||||
return patch
|
return patch
|
||||||
end
|
end
|
||||||
|
|
||||||
|
nextId += 1
|
||||||
|
local id = nextId
|
||||||
|
|
||||||
setmetatable(component, {
|
setmetatable(component, {
|
||||||
__call = function(_, ...)
|
__call = function(_, ...)
|
||||||
return component.new(...)
|
return component.new(...)
|
||||||
|
@ -327,6 +330,9 @@ local function newComponent(name, defaultData)
|
||||||
__tostring = function()
|
__tostring = function()
|
||||||
return name
|
return name
|
||||||
end,
|
end,
|
||||||
|
__len = function()
|
||||||
|
return id
|
||||||
|
end,
|
||||||
[DIAGNOSTIC_COMPONENT_MARKER] = true,
|
[DIAGNOSTIC_COMPONENT_MARKER] = true,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue