Skip to content

fix: xlua didn't print calling stack when throwing error from coroutine #1082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion Assets/XLua/Resources/xlua/util.lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ local function coroutine_call(func)
end
end

local function coroutine_wrap(func)
local thread = coroutine.create(func)
return function(...)
_GlobalCorThread_ = thread --for outside code,usage: _GlobalCorThread_ and debug.traceback(_GlobalCorThread_) or debug.traceback()
local results = table.pack(coroutine.resume(thread, ...)) --{true/false, data1/errormsg, data2...}
_GlobalCorThread_ = nil
if not results[1] then
local errStr = string.format('%s\n%s',results[2], debug.traceback(thread))
error(errStr, 2) --skip 1 stack level
-- print("====!!!!!!!!!!!!!!!!!!") //never run
end
return table.unpack(results, 2) --, results.n) --drop true
end
end

local move_end = {}

local generator_mt = {
Expand All @@ -51,7 +66,7 @@ local generator_mt = {
end
end;
Reset = function(self)
self.co = coroutine.wrap(self.w_func)
self.co = coroutine_wrap(self.w_func)
end
}
}
Expand Down