[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: pcall() and coroutine.yield()
- From: Roberto Ierusalimschy <roberto@...>
- Date: Mon, 18 Oct 2004 16:37:04 -0200
> Will lua 5.1 help?
No (unfortunately).
> Opinions? Suggestions?
If you really need that, you could try to create your own version of
"pcall" that runs its argument as a new coroutine. This new pcall
passes resumes and yields from one coroutine to the other and handle
errors when necessary. Something more or less like this:
function mypcall (f, arg)
local co = coroutine.create(f)
while true do
local status, val = coroutine.resume(co, arg)
if coroutine.status(co) ~= "suspended" then
return status, val -- error or normal return
else
arg = coroutine.yield(val) -- suspend across `mypcall'
end
end
end
(This is untested code! I hope at least the concept is correct :)
-- Roberto