updates
This commit is contained in:
parent
7e506f79c9
commit
5d363f4fa7
@ -73,6 +73,10 @@ Going Forward:
|
||||
---
|
||||
- There is no longer any plans for sterilization! Functions do not play nice on different platforms and there is no simple way to ensure that things work.
|
||||
|
||||
Quality Of Life:
|
||||
---
|
||||
- threaded functions now return only the arguments that are needed, if it has trailing nils, they wont be returned like they used to.
|
||||
|
||||
Added:
|
||||
---
|
||||
- Type: destroyed
|
||||
|
||||
@ -1090,6 +1090,18 @@ function multi.holdFor(n,func)
|
||||
end
|
||||
end)
|
||||
end
|
||||
local function cleanReturns(...)
|
||||
local n = select("#", ...)
|
||||
local returns = {...}
|
||||
local rets = {}
|
||||
local ind = 0
|
||||
for i=n,1,-1 do
|
||||
if returns[i] then
|
||||
ind=i
|
||||
end
|
||||
end
|
||||
return unpack(returns,1,ind)
|
||||
end
|
||||
function thread:newFunction(func,holdme)
|
||||
return function(...)
|
||||
local rets, err
|
||||
@ -1099,7 +1111,7 @@ function thread:newFunction(func,holdme)
|
||||
if err then
|
||||
return multi.NIL, err
|
||||
elseif rets then
|
||||
return (rets[1] or multi.NIL),rets[2],rets[3],rets[4],rets[5],rets[6],rets[7]
|
||||
return cleanReturns((rets[1] or multi.NIL),rets[2],rets[3],rets[4],rets[5],rets[6],rets[7])
|
||||
end
|
||||
end)
|
||||
else
|
||||
@ -1109,11 +1121,11 @@ function thread:newFunction(func,holdme)
|
||||
if err then
|
||||
return nil,err
|
||||
end
|
||||
return rets[1],rets[2],rets[3],rets[4],rets[5],rets[6],rets[7]
|
||||
return cleanReturns(rets[1],rets[2],rets[3],rets[4],rets[5],rets[6],rets[7])
|
||||
end
|
||||
end
|
||||
local t = multi:newThread("TempThread",func,...)
|
||||
t.OnDeath(function(self,status,a1,a2,a3,a4,a5,a6,a7) rets = {a1,a2,a3,a4,a5,a6,a7} end)
|
||||
t.OnDeath(function(self,status,...) rets = {...} end)
|
||||
t.OnError(function(self,e) err = e end)
|
||||
if holdme then
|
||||
return wait()
|
||||
@ -1122,7 +1134,7 @@ function thread:newFunction(func,holdme)
|
||||
isTFunc = true,
|
||||
wait = wait,
|
||||
connect = function(f)
|
||||
t.OnDeath(function(self,status,...) f(...) end)
|
||||
t.OnDeath(function(self,status,...) f(cleanReturns(...)) end)
|
||||
t.OnError(function(self,err) f(err) end)
|
||||
end
|
||||
}
|
||||
|
||||
29
test.lua
29
test.lua
@ -1,14 +1,23 @@
|
||||
package.path="?.lua;?/init.lua;?.lua;?/?/init.lua;"..package.path
|
||||
multi, thread = require("multi"):init()
|
||||
a=0
|
||||
local function cleanReturns(...)
|
||||
local n = select("#", ...)
|
||||
print(n)
|
||||
local returns = {...}
|
||||
local rets = {}
|
||||
local ind = 0
|
||||
for i=n,1,-1 do
|
||||
if returns[i] then
|
||||
ind=i
|
||||
end
|
||||
end
|
||||
return unpack(returns,1,ind)
|
||||
end
|
||||
func = thread:newFunction(function()
|
||||
print(thread.holdFor(3,function()
|
||||
return a==5
|
||||
end))
|
||||
print(thread.hold(function()
|
||||
return multi.NIL,"test"
|
||||
end))
|
||||
end,true) -- Tell the code to wait and then return
|
||||
a,b = func()
|
||||
print(a,b)
|
||||
multi:lightloop()
|
||||
return thread.holdFor(3,function()
|
||||
return a==5 -- Condition being tested!
|
||||
end)
|
||||
end,true)
|
||||
print(func())
|
||||
--multi:lightloop()
|
||||
Loading…
x
Reference in New Issue
Block a user