mirror of
https://github.com/rayaman/multi.git
synced 2026-09-05 07:27:35 -04:00
new pack/unpack for tables, current issue is things being turned into strings
This commit is contained in:
+88
-44
@@ -1,50 +1,94 @@
|
||||
package.path = "../?/init.lua;../?.lua;"..package.path
|
||||
local multi, thread = require("multi"):init{print=true, warning = true, error=true}
|
||||
local flat = require("flatten")
|
||||
|
||||
GLOBAL, THREAD = require("multi.integration.loveManager"):init()
|
||||
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 queue = multi:newSystemThreadedQueue("TestQueue")
|
||||
local tab = multi:newSystemThreadedTable("TestTable")
|
||||
|
||||
local test = multi:newSystemThread("Test",function()
|
||||
local queue = THREAD.waitFor("TestQueue")
|
||||
local tab = THREAD.waitFor("TestTable")
|
||||
print("THREAD_ID:",THREAD_ID)
|
||||
queue:push("Did it work?")
|
||||
tab["Test"] = true
|
||||
return 1,2,3
|
||||
end)
|
||||
|
||||
multi:newThread("QueueTest", function()
|
||||
print(thread.hold(queue))
|
||||
print(thread.hold(tab, {key="Test"}))
|
||||
print("Done!")
|
||||
end)
|
||||
|
||||
local jq = multi:newSystemThreadedJobQueue(n)
|
||||
|
||||
jq:registerFunction("test2",function()
|
||||
print("This works!")
|
||||
end)
|
||||
|
||||
jq:registerFunction("test",function(a, b, c)
|
||||
print(a, b+c)
|
||||
test2()
|
||||
return a+b+c
|
||||
end)
|
||||
|
||||
print("Job:",jq:pushJob("test",1,2,3))
|
||||
print("Job:",jq:pushJob("test",2,3,4))
|
||||
print("Job:",jq:pushJob("test",5,6,7))
|
||||
|
||||
jq.OnJobCompleted(function(...)
|
||||
print("Job Completed!", ...)
|
||||
end)
|
||||
|
||||
function love.draw()
|
||||
--
|
||||
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) .. ','
|
||||
end
|
||||
return s .. '} '
|
||||
else
|
||||
return tostring(o)
|
||||
end
|
||||
end
|
||||
|
||||
function love.update()
|
||||
multi:uManager()
|
||||
end
|
||||
local fpeople = flat.flatten(people)
|
||||
|
||||
print("Flatten", dump(fpeople))
|
||||
|
||||
local people = flat.unflatten(fpeople)
|
||||
|
||||
print("Unflatten", dump(people))
|
||||
|
||||
-- GLOBAL, THREAD = require("multi.integration.loveManager"):init()
|
||||
|
||||
-- local queue = multi:newSystemThreadedQueue("TestQueue")
|
||||
-- local tab = multi:newSystemThreadedTable("TestTable")
|
||||
|
||||
-- local test = multi:newSystemThread("Test",function()
|
||||
-- local queue = THREAD.waitFor("TestQueue")
|
||||
-- local tab = THREAD.waitFor("TestTable")
|
||||
-- print("THREAD_ID:",THREAD_ID)
|
||||
-- queue:push("Did it work?")
|
||||
-- tab["Test"] = true
|
||||
-- return 1,2,3
|
||||
-- end)
|
||||
|
||||
-- multi:newThread("QueueTest", function()
|
||||
-- print(thread.hold(queue))
|
||||
-- print(thread.hold(tab, {key="Test"}))
|
||||
-- print("Done!")
|
||||
-- end)
|
||||
|
||||
-- local jq = multi:newSystemThreadedJobQueue(n)
|
||||
|
||||
-- jq:registerFunction("test2",function()
|
||||
-- print("This works!")
|
||||
-- end)
|
||||
|
||||
-- jq:registerFunction("test",function(a, b, c)
|
||||
-- print(a, b+c)
|
||||
-- test2()
|
||||
-- return a+b+c
|
||||
-- end)
|
||||
|
||||
-- print("Job:",jq:pushJob("test",1,2,3))
|
||||
-- print("Job:",jq:pushJob("test",2,3,4))
|
||||
-- print("Job:",jq:pushJob("test",5,6,7))
|
||||
|
||||
-- jq.OnJobCompleted(function(...)
|
||||
-- print("Job Completed!", ...)
|
||||
-- end)
|
||||
|
||||
-- function love.draw()
|
||||
-- --
|
||||
-- end
|
||||
|
||||
-- function love.update()
|
||||
-- multi:uManager()
|
||||
-- end
|
||||
Reference in New Issue
Block a user