testing
This commit is contained in:
parent
08831e1dcb
commit
ff7f46393f
@ -29,9 +29,10 @@ local thread = {}
|
||||
if not _G["$multi"] then
|
||||
_G["$multi"] = {multi=multi,thread=thread}
|
||||
end
|
||||
|
||||
multi.Version = "14.2.0"
|
||||
multi.stage = "stable"
|
||||
multi.__index = multi
|
||||
--multi.__index = multi
|
||||
multi.Name = "multi.root"
|
||||
multi.Mainloop = {}
|
||||
multi.Garbage = {}
|
||||
@ -312,9 +313,9 @@ function multi:newBase(ins)
|
||||
if not(self.Type=='mainprocess' or self.Type=='process' or self.Type=='queue') then error('Can only create an object on multi or an interface obj') return false end
|
||||
local c = {}
|
||||
if self.Type=='process' or self.Type=='queue' then
|
||||
setmetatable(c, self.Parent)
|
||||
setmetatable(c, {__index = multi}) -- setmetatable(c, {__index = multi})
|
||||
else
|
||||
setmetatable(c, self)
|
||||
setmetatable(c, {__index = multi})
|
||||
end
|
||||
c.Active=true
|
||||
c.func={}
|
||||
@ -519,7 +520,7 @@ ignoreconn = false
|
||||
function multi:newProcessor(file)
|
||||
if not(self.Type=='mainprocess') then error('Can only create an interface on the multi obj') return false end
|
||||
local c = {}
|
||||
setmetatable(c, self)
|
||||
setmetatable(c, {__index = multi})
|
||||
c.Parent=self
|
||||
c.Active=true
|
||||
c.func={}
|
||||
|
||||
119
test.lua
119
test.lua
@ -1,54 +1,79 @@
|
||||
package.path="?.lua;?/init.lua;?.lua;?/?/init.lua;"..package.path
|
||||
-- local sterilizer = require("multi.integration.sterilization")
|
||||
multi,thread = require("multi"):init()
|
||||
local function inList(t,o,n)
|
||||
local c = 1
|
||||
if not o["$__COUNTER__$"] then
|
||||
o["$__COUNTER__$"] = 1
|
||||
end
|
||||
if o["$__COUNTER__$"]==n then
|
||||
return o
|
||||
end
|
||||
for i,v in pairs(t) do
|
||||
if v==o then
|
||||
o["$__COUNTER__$"] = o["$__COUNTER__$"] + 1
|
||||
if o["$__COUNTER__$"]==n then
|
||||
return o
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
function initLoop(t,max)
|
||||
for i,v in pairs(t) do
|
||||
v["$__COUNTER__$"] = max
|
||||
end
|
||||
return t
|
||||
end
|
||||
function _getPath(tbl, obj, conn, loop, path, orig)
|
||||
local max = 100
|
||||
if not loop then loop = initLoop({package,_G,math,io,os,debug,string,table,coroutine},max) end
|
||||
if not path then path = {} end
|
||||
if not ref then ref = {} end
|
||||
for k, v in pairs(tbl) do
|
||||
if type(v) == "table" and type(k)~="number" and not inList(loop,v,max) then -- Only go this deep
|
||||
if v~=orig and k=="Parent" then
|
||||
--
|
||||
else
|
||||
--print(table.concat(path,".").."."..k)
|
||||
table.insert(ref,v)
|
||||
table.insert(loop,v)
|
||||
table.insert(path,k)
|
||||
if v==obj then
|
||||
conn(table.concat(path,".").."."..k,ref)
|
||||
end
|
||||
_getPath(v, obj, conn, loop, path, orig)
|
||||
table.remove(path)
|
||||
table.remove(ref)
|
||||
end
|
||||
end
|
||||
if v==obj and orig[k] then
|
||||
conn(k,ref)
|
||||
elseif v==obj then
|
||||
if type(k)=="number" then return end
|
||||
local str = table.concat(path,".").."."..k
|
||||
conn(str,ref)
|
||||
end
|
||||
end
|
||||
end
|
||||
function getPath(tbl,obj)
|
||||
local instances = {}
|
||||
_getPath(tbl, obj, function(ins)
|
||||
table.insert(instances,ins)
|
||||
end,nil,nil,tbl)
|
||||
local min = math.huge
|
||||
local ins
|
||||
for i,v in pairs(instances) do
|
||||
if #v<min then
|
||||
ins = v
|
||||
min = #v
|
||||
end
|
||||
end
|
||||
return ins or false
|
||||
end
|
||||
test = {}
|
||||
test.temp = {}
|
||||
test.temp.hello = multi:newAlarm(3)
|
||||
local function inList(t,o)
|
||||
for i,v in pairs(t) do
|
||||
if v==o then
|
||||
return v
|
||||
end
|
||||
end
|
||||
end
|
||||
local function convertFunc(func)
|
||||
local c = {}
|
||||
c.func = func
|
||||
c.__call = function(self,...)
|
||||
if self.called then return unpack(self.rets) end
|
||||
self.rets = {self.func(...)}
|
||||
self.called = true
|
||||
return unpack(self.rets)
|
||||
end
|
||||
setmetatable(c,c)
|
||||
return c
|
||||
end
|
||||
function getPath(tbl, obj, conn, indent, loop, path)
|
||||
conn = convertFunc(conn)
|
||||
if not indent then indent = 0 end
|
||||
if not loop then loop = {} end
|
||||
if not path then path = {"\0"} end
|
||||
for k, v in pairs(tbl) do
|
||||
formatting = string.rep(" ", indent) .. k .. ": "
|
||||
if type(v) == "table" then
|
||||
if not inList(loop,v) and type(k)~="number" then
|
||||
table.insert(loop,v)
|
||||
table.insert(path,k)
|
||||
getPath(v, obj, conn, indent + 1, loop, path)
|
||||
table.remove(path)
|
||||
end
|
||||
end
|
||||
if v==obj then
|
||||
if type(k)=="number" then return end
|
||||
local str = table.concat(path,".").."."..k
|
||||
str = str:reverse()
|
||||
conn(str:sub(1,(str:find("\0"))-2):reverse())
|
||||
return
|
||||
end
|
||||
end
|
||||
--conn(nil,"Path not found")
|
||||
end
|
||||
local hmm = test.temp.hello
|
||||
getPath(_G, hmm, function(path)
|
||||
print(path)
|
||||
end)
|
||||
print(getPath(_G, hmm))
|
||||
print(getPath(_G, multi.Garbage)) -- Cannot index into multi because of __index
|
||||
print(getPath(_G, multi.DestroyedObj))
|
||||
Loading…
x
Reference in New Issue
Block a user