From c5daddd50595c6add7f4c2251f9ea6af7353c7e1 Mon Sep 17 00:00:00 2001 From: Ukendio Date: Fri, 3 May 2024 15:31:16 +0200 Subject: [PATCH] Increment component id --- newMatter.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/newMatter.lua b/newMatter.lua index 4cfe879..150bbb8 100644 --- a/newMatter.lua +++ b/newMatter.lua @@ -265,9 +265,9 @@ local topoRuntime = { -- It should not be accessible through indexing into a component instance directly. local DIAGNOSTIC_COMPONENT_MARKER = {} +local nextId = 0 local function newComponent(name, defaultData) name = name or debug.info(2, "s") .. "@" .. debug.info(2, "l") - assert( defaultData == nil or type(defaultData) == "table", "if component default data is specified, it must be a table" @@ -320,6 +320,9 @@ local function newComponent(name, defaultData) return patch end + nextId += 1 + local id = nextId + setmetatable(component, { __call = function(_, ...) return component.new(...) @@ -327,6 +330,9 @@ local function newComponent(name, defaultData) __tostring = function() return name end, + __len = function() + return id + end, [DIAGNOSTIC_COMPONENT_MARKER] = true, })