@time4coding - try this, it’s a bit of a kludge because it loops through every object in memory to get the list - but it is fast. The variable _G is worth exploring, it is a table holding absolutely everything.
function setup()
mt={}
t=setmetatable({},mt)
t2=setmetatable({},mt)
list=GetTableList(mt)
print(t==list[1],t2==list[2]) --check it worked
end
function GetTableList(m)
local list={}
for n,v in pairs(_G) do --look at everything
if type(v)=="table" then
local mt=getmetatable(v)
if mt==m then table.insert(list,v) end
end
end
return list
end
You probably want to access only some special metatables, corresponding to some class you’ve created? If so you can simply record each object when it is created:
--# example
example = class()
example.list = {}
function example:init(name)
self.name = name
table.insert(example.list,self)
end
--# Main
-- class list
function setup()
ex1 = example("name 1")
ex2 = example("name 2")
for k,v in pairs(example.list) do
print(v.name)
end
end
here example variable is the metatable of every object you create with example("xx"), so it looks pretty much like what you wanted (a list of all objects with this metatable).