summaryrefslogtreecommitdiff
path: root/indra/newview
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview')
-rw-r--r--indra/newview/scripts/lua/coro.lua24
1 files changed, 17 insertions, 7 deletions
diff --git a/indra/newview/scripts/lua/coro.lua b/indra/newview/scripts/lua/coro.lua
index 8f868f5a48..616a797e95 100644
--- a/indra/newview/scripts/lua/coro.lua
+++ b/indra/newview/scripts/lua/coro.lua
@@ -5,15 +5,25 @@ local coro = {}
coro._coros = {}
-- Launch a Lua coroutine: create and resume.
--- Returns:
--- new coroutine
--- bool ok
--- if not ok: error message
--- if ok: values yielded or returned
+-- Returns: new coroutine, values yielded or returned from initial resume()
+-- If initial resume() encountered an error, propagates the error.
function coro.launch(func, ...)
local co = coroutine.create(func)
table.insert(coro._coros, co)
- return co, coroutine.resume(co, ...)
+ return co, coro.resume(co, ...)
+end
+
+-- resume() wrapper to propagate errors
+function coro.resume(co, ...)
+ -- if there's an idiom other than table.pack() to assign an arbitrary
+ -- number of return values, I don't yet know it
+ local ok_result = table.pack(coroutine.resume(co, ...))
+ if not ok_result[1] then
+ -- if [1] is false, then [2] is the error message
+ error(ok_result[2])
+ end
+ -- ok is true, whew, just return the rest of the values
+ return table.unpack(ok_result, 2)
end
-- yield to other coroutines even if you don't know whether you're in a
@@ -28,7 +38,7 @@ function coro.yield(...)
-- Walk a copy of coro._coros in case any of these coroutines launches
-- another: next() forbids creating new entries during traversal.
for co in coro._live_coros_iter, table.clone(coro._coros) do
- co.resume()
+ coro.resume(co)
end
end
end