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