Sterilization being worked on

This commit is contained in:
Ryan Ward 2020-02-27 08:49:45 -05:00
parent b251758790
commit 08831e1dcb
2 changed files with 31 additions and 6 deletions

View File

@ -25,6 +25,16 @@ local bin = pcall(require,"bin")
if not bin then return error("The bin library is required to use sterilization!") end
local multi,thread = require("multi"):init()
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
---------------------

View File

@ -4,23 +4,34 @@ multi,thread = require("multi"):init()
test = {}
test.temp = {}
test.temp.hello = multi:newAlarm(3)
function inList(t,o)
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 = {"_G"} end
if not path then path = {"\0"} end
for k, v in pairs(tbl) do
formatting = string.rep(" ", indent) .. k .. ": "
--print(k,v==obj)
if type(v) == "table" then
if not inList(loop,v) and type(k)~="number" then
--print(formatting)
table.insert(loop,v)
table.insert(path,k)
getPath(v, obj, conn, indent + 1, loop, path)
@ -28,12 +39,16 @@ function getPath(tbl, obj, conn, indent, loop, 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("G_"))+1):reverse())
conn(str:sub(1,(str:find("\0"))-2):reverse())
return
end
end
--conn(nil,"Path not found")
end
getPath(_G, test.temp.hello.Act,function(path)
local hmm = test.temp.hello
getPath(_G, hmm, function(path)
print(path)
end)