Fixed packing of values into threads, need to fix system proxies and system threaded processors

This commit is contained in:
2023-08-01 23:45:06 -04:00
parent bb0592f3eb
commit 59cbeb6597
5 changed files with 27 additions and 40 deletions
+3 -2
View File
@@ -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()
+1 -2
View File
@@ -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({},
{
+10 -7
View File
@@ -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