Fixed issue with yielding across c/metamethod boundaries. Forgot that my default lua was luajit
This commit is contained in:
parent
c251567804
commit
6dbf2f5e93
@ -1416,8 +1416,8 @@ function thread.waitFor(name)
|
||||
thread.hold(function() return thread.get(name)~=nil end)
|
||||
return thread.get(name)
|
||||
end
|
||||
function multi.hold(func)
|
||||
if thread.isThread() then
|
||||
function multi.hold(func,no)
|
||||
if thread.isThread() and not(no) then
|
||||
if type(func) == "function" or type(func) == "table" then
|
||||
return thread.hold(func)
|
||||
end
|
||||
@ -1462,9 +1462,9 @@ function thread:newFunction(func)
|
||||
local c = {Type = "tfunc"}
|
||||
c.__call = function(self,...)
|
||||
local rets, err
|
||||
local function wait()
|
||||
if thread.isThread() then
|
||||
return thread.hold(function()
|
||||
local function wait(no)
|
||||
if thread.isThread() and not (no) then
|
||||
return multi.hold(function()
|
||||
if err then
|
||||
return multi.NIL, err
|
||||
elseif rets then
|
||||
@ -1551,16 +1551,18 @@ function multi:newThread(name,func,...)
|
||||
if not _G["_stack_"] or #_G["_stack_"]==0 then
|
||||
_G["_stack_"] = {}
|
||||
local s = _G["_stack_"]
|
||||
local a,b,c,d,e,f,g = v.wait()
|
||||
local a,b,c,d,e,f,g = v.wait(true)
|
||||
table.insert(s,a)
|
||||
table.insert(s,b)
|
||||
table.insert(s,c)
|
||||
table.insert(s,d)
|
||||
table.insert(s,e)
|
||||
table.insert(s,f)
|
||||
Gref[k]=table.remove(_G["_stack_"])
|
||||
local x = table.remove(_G["_stack_"])
|
||||
Gref[k]=x
|
||||
else
|
||||
Gref[k]=table.remove(_G["_stack_"])
|
||||
local x = table.remove(_G["_stack_"])
|
||||
Gref[k]=x
|
||||
end
|
||||
else
|
||||
Gref[k]=v
|
||||
@ -1707,7 +1709,9 @@ function multi.initThreads(justThreads)
|
||||
multi.scheduler:OnLoop(function(self)
|
||||
for i=#threads,1,-1 do
|
||||
if not threads[i].__started then
|
||||
_,ret,r1,r2,r3,r4,r5,r6=coroutine.resume(threads[i].thread,unpack(threads[i].startArgs))
|
||||
if coroutine.running() ~= threads[i].thread then
|
||||
_,ret,r1,r2,r3,r4,r5,r6=coroutine.resume(threads[i].thread,t0,t1,t2,t3,t4,t5,t6)
|
||||
end
|
||||
threads[i].__started = true
|
||||
helper(i)
|
||||
end
|
||||
@ -1763,8 +1767,10 @@ function multi.initThreads(justThreads)
|
||||
end
|
||||
if threads[i] and threads[i].__ready then
|
||||
threads[i].__ready = false
|
||||
if coroutine.running() ~= threads[i].thread then
|
||||
_,ret,r1,r2,r3,r4,r5,r6=coroutine.resume(threads[i].thread,t0,t1,t2,t3,t4,t5,t6)
|
||||
end
|
||||
end
|
||||
helper(i)
|
||||
end
|
||||
end)
|
||||
|
||||
9
test.lua
9
test.lua
@ -5,14 +5,13 @@ multi:newThread(function()
|
||||
thread.sleep(1)
|
||||
return 1,2
|
||||
end
|
||||
-- This returns instantly even though the function isn't done!
|
||||
test().connect(function(...)
|
||||
print(...)
|
||||
--This returns instantly even though the function isn't done!
|
||||
test().connect(function(a,b)
|
||||
print("Connected:",a,b)
|
||||
end)
|
||||
print("Done")
|
||||
-- This waits for the returns since we are demanding them
|
||||
a,b = test()
|
||||
print(a,b)
|
||||
print("Waited:",a,b)
|
||||
os.exit()
|
||||
end)
|
||||
--min,hour,day,wday,month
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user