Sterilization being worked on
This commit is contained in:
parent
b251758790
commit
08831e1dcb
@ -25,6 +25,16 @@ local bin = pcall(require,"bin")
|
|||||||
if not bin then return error("The bin library is required to use sterilization!") end
|
if not bin then return error("The bin library is required to use sterilization!") end
|
||||||
local multi,thread = require("multi"):init()
|
local multi,thread = require("multi"):init()
|
||||||
local sterilizer = {}
|
local sterilizer = {}
|
||||||
|
----------
|
||||||
|
-- Helpers
|
||||||
|
----------
|
||||||
|
local function inList(t,o)
|
||||||
|
for i,v in pairs(t) do
|
||||||
|
if v==o then
|
||||||
|
return v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
---------------------
|
---------------------
|
||||||
-- State Saving Stuff
|
-- State Saving Stuff
|
||||||
---------------------
|
---------------------
|
||||||
|
|||||||
27
test.lua
27
test.lua
@ -4,23 +4,34 @@ multi,thread = require("multi"):init()
|
|||||||
test = {}
|
test = {}
|
||||||
test.temp = {}
|
test.temp = {}
|
||||||
test.temp.hello = multi:newAlarm(3)
|
test.temp.hello = multi:newAlarm(3)
|
||||||
function inList(t,o)
|
local function inList(t,o)
|
||||||
for i,v in pairs(t) do
|
for i,v in pairs(t) do
|
||||||
if v==o then
|
if v==o then
|
||||||
return v
|
return v
|
||||||
end
|
end
|
||||||
end
|
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)
|
function getPath(tbl, obj, conn, indent, loop, path)
|
||||||
|
conn = convertFunc(conn)
|
||||||
if not indent then indent = 0 end
|
if not indent then indent = 0 end
|
||||||
if not loop then loop = {} end
|
if not loop then loop = {} end
|
||||||
if not path then path = {"_G"} end
|
if not path then path = {"\0"} end
|
||||||
for k, v in pairs(tbl) do
|
for k, v in pairs(tbl) do
|
||||||
formatting = string.rep(" ", indent) .. k .. ": "
|
formatting = string.rep(" ", indent) .. k .. ": "
|
||||||
--print(k,v==obj)
|
|
||||||
if type(v) == "table" then
|
if type(v) == "table" then
|
||||||
if not inList(loop,v) and type(k)~="number" then
|
if not inList(loop,v) and type(k)~="number" then
|
||||||
--print(formatting)
|
|
||||||
table.insert(loop,v)
|
table.insert(loop,v)
|
||||||
table.insert(path,k)
|
table.insert(path,k)
|
||||||
getPath(v, obj, conn, indent + 1, loop, path)
|
getPath(v, obj, conn, indent + 1, loop, path)
|
||||||
@ -28,12 +39,16 @@ function getPath(tbl, obj, conn, indent, loop, path)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
if v==obj then
|
if v==obj then
|
||||||
|
if type(k)=="number" then return end
|
||||||
local str = table.concat(path,".").."."..k
|
local str = table.concat(path,".").."."..k
|
||||||
str = str:reverse()
|
str = str:reverse()
|
||||||
conn(str:sub(1,(str:find("G_"))+1):reverse())
|
conn(str:sub(1,(str:find("\0"))-2):reverse())
|
||||||
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
--conn(nil,"Path not found")
|
||||||
end
|
end
|
||||||
getPath(_G, test.temp.hello.Act,function(path)
|
local hmm = test.temp.hello
|
||||||
|
getPath(_G, hmm, function(path)
|
||||||
print(path)
|
print(path)
|
||||||
end)
|
end)
|
||||||
Loading…
x
Reference in New Issue
Block a user