Fixed packing of values into threads, need to fix system proxies and system threaded processors
This commit is contained in:
parent
bb0592f3eb
commit
59cbeb6597
@ -9,6 +9,7 @@ THREAD_ID = table.remove(args, 1)
|
||||
THREAD_NAME = table.remove(args, 1)
|
||||
GLOBAL, THREAD = require("multi.integration.loveManager.threads"):init()
|
||||
__FUNC = THREAD.unpackValue(table.remove(args, 1))
|
||||
ARGS = THREAD.unpackValue(table.remove(args, 1))
|
||||
math.randomseed(THREAD_ID)
|
||||
math.random()
|
||||
math.random()
|
||||
@ -23,7 +24,7 @@ end
|
||||
multi, thread = require("multi"):init()
|
||||
require("multi.integration.loveManager.extensions")
|
||||
require("multi.integration.sharedExtensions")
|
||||
stab["returns"] = {__FUNC(multi.unpack(args))}
|
||||
stab["returns"] = {__FUNC(multi.unpack(ARGS))}
|
||||
]]
|
||||
|
||||
_G.THREAD_NAME = "MAIN_THREAD"
|
||||
@ -45,7 +46,7 @@ function multi:newSystemThread(name, func, ...)
|
||||
c.Name = name
|
||||
c.ID = tid
|
||||
c.thread = love.thread.newThread(ThreadFileData)
|
||||
c.thread:start(c.ID, c.Name, THREAD.packValue(func), ...)
|
||||
c.thread:start(c.ID, c.Name, THREAD.packValue(func), THREAD.packValue({...}))
|
||||
c.stab = THREAD.createTable(name .. c.ID)
|
||||
c.creationTime = os.clock()
|
||||
c.OnDeath = multi:newConnection()
|
||||
|
||||
@ -52,8 +52,7 @@ local function createTable(n)
|
||||
chan:push(packValue(val))
|
||||
end
|
||||
local function get(name)
|
||||
local dat = love.thread.getChannel(n .. name):peek()
|
||||
return unpackValue(dat)
|
||||
return unpackValue(love.thread.getChannel(n .. name):peek())
|
||||
end
|
||||
return setmetatable({},
|
||||
{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
require("love.data")
|
||||
local sutils = {}
|
||||
local utils = {}
|
||||
local NIL = {Type="nil"}
|
||||
|
||||
--love.data.newByteData("\2"..serpent.dump({t,true},{safe = true}))
|
||||
@ -13,21 +13,22 @@ local t = function(value)
|
||||
else return v end
|
||||
end
|
||||
|
||||
function sutils.pack(tbl, seen)
|
||||
function utils.pack(tbl, seen)
|
||||
if type(tbl) == "function" then return {["__$FUNC$__"] = love.data.newByteData(string.dump(tbl))} end
|
||||
if type(tbl) ~= "table" then return tbl end
|
||||
local seen = seen or {}
|
||||
local result = {}
|
||||
result.__isPacked = true
|
||||
for i,v in pairs(tbl) do
|
||||
if seen[v] then
|
||||
result[i] = v
|
||||
elseif t(v) == "table" then
|
||||
seen[v] = true
|
||||
result[i] = sutils.pack(v, seen)
|
||||
result[i] = utils.pack(v, seen)
|
||||
elseif t(v) == "function" then
|
||||
result["$F"..i] = love.data.newByteData(string.dump(v))
|
||||
elseif t{v} == "userdata" then
|
||||
result[i] = tostring(v)
|
||||
result[i] = "userdata"
|
||||
else -- Handle what we need to and pass the rest along as a value
|
||||
result[i] = v
|
||||
end
|
||||
@ -35,7 +36,8 @@ function sutils.pack(tbl, seen)
|
||||
return result
|
||||
end
|
||||
|
||||
function sutils.unpack(tbl)
|
||||
function utils.unpack(tbl)
|
||||
if not tbl then return nil end
|
||||
if type(tbl) ~= "table" then return tbl end
|
||||
if tbl["__$FUNC$__"] then return loadstring(tbl["__$FUNC$__"]:getString()) end
|
||||
for i,v in pairs(tbl) do
|
||||
@ -46,10 +48,11 @@ function sutils.unpack(tbl)
|
||||
tbl[i:sub(3,-1)] = loadstring(rawfunc)
|
||||
end
|
||||
if type(v) == "table" then
|
||||
sutils.unpack(v)
|
||||
utils.unpack(v)
|
||||
end
|
||||
end
|
||||
tbl.__isPacked = nil
|
||||
return tbl
|
||||
end
|
||||
|
||||
return sutils
|
||||
return utils
|
||||
@ -1,35 +1,15 @@
|
||||
package.path = "../?/init.lua;../?.lua;"..package.path
|
||||
local multi, thread = require("multi"):init{print=true, warning = true, error=true}
|
||||
local flat = require("flatten")
|
||||
local utils = require("multi.integration.loveManager.utils")
|
||||
|
||||
local people = {
|
||||
{
|
||||
name = "Fred",
|
||||
address = "16 Long Street",
|
||||
phone = "123456"
|
||||
},
|
||||
{
|
||||
name = "Wilma",
|
||||
address = "16 Long Street",
|
||||
phone = "123456",
|
||||
func = function()
|
||||
print("Hi")
|
||||
end
|
||||
},
|
||||
{
|
||||
name = "Barney",
|
||||
address = "17 Long Street",
|
||||
phone = "123457",
|
||||
important = love.data.newByteData("TEST")
|
||||
}
|
||||
}
|
||||
local people = {1,2,3}
|
||||
|
||||
function dump(o)
|
||||
if type(o) == 'table' then
|
||||
local s = '{ '
|
||||
for k,v in pairs(o) do
|
||||
if type(k) ~= 'number' then k = '"'..k..'"' end
|
||||
s = s .. '['..k..'] = ' .. dump(v) .. ','
|
||||
s = s .. '['..k..'] = ' .. dump(v) .. '('..type(v):sub(1,1)..'),'
|
||||
end
|
||||
return s .. '} '
|
||||
else
|
||||
@ -37,13 +17,14 @@ function dump(o)
|
||||
end
|
||||
end
|
||||
|
||||
local fpeople = flat.flatten(people)
|
||||
local fpeople = utils.pack(people)
|
||||
|
||||
print("Flatten", dump(fpeople))
|
||||
print("Pack:", dump(fpeople))
|
||||
|
||||
local people = flat.unflatten(fpeople)
|
||||
local people = utils.unpack(fpeople)
|
||||
|
||||
print("Unflatten", dump(people))
|
||||
print("Unpack:", dump(people))
|
||||
print(type(people[3]))
|
||||
|
||||
-- GLOBAL, THREAD = require("multi.integration.loveManager"):init()
|
||||
|
||||
|
||||
@ -55,6 +55,9 @@ multi:newThread("Scheduler Thread",function()
|
||||
multi_assert("Passing some args", a, "First argument is not as expected 'Passing some args'")
|
||||
multi_assert(true, e, "Argument e is not true!")
|
||||
multi_assert("table", type(f), "Argument f is not a table!")
|
||||
for i,v in pairs(queue) do
|
||||
print("Queue:",i,v)
|
||||
end
|
||||
queue:push("done")
|
||||
end,"Passing some args", 1, 2, 3, true, {"Table"}).OnError(function(self,err)
|
||||
multi.error(err)
|
||||
@ -90,14 +93,14 @@ multi:newThread("Scheduler Thread",function()
|
||||
local worked = false
|
||||
|
||||
multi:newSystemThread("testing tables",function()
|
||||
tab=THREAD.waitFor("YO"):init()
|
||||
tab=THREAD.waitFor("YO")
|
||||
THREAD.hold(function() return tab["test1"] end)
|
||||
THREAD.sleep(.1)
|
||||
tab["test2"] = "Whats so funny?"
|
||||
end).OnError(multi.error)
|
||||
|
||||
multi:newThread("test2",function()
|
||||
thread.hold(function() return test["test2"] end)
|
||||
print(thread.hold(function() return test["test2"] end))
|
||||
worked = true
|
||||
end)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user