diff options
Diffstat (limited to 'compat53/base.lua')
| -rw-r--r-- | compat53/base.lua | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/compat53/base.lua b/compat53/base.lua index 370909a..8fbc71f 100644 --- a/compat53/base.lua +++ b/compat53/base.lua | |||
| @@ -378,12 +378,21 @@ if lua_version < "5.3" then | |||
| 378 | M.package = setmetatable({}, { __index = package }) | 378 | M.package = setmetatable({}, { __index = package }) |
| 379 | 379 | ||
| 380 | 380 | ||
| 381 | -- table that maps each running coroutine to the coroutine that resumed it | 381 | -- the (x)pcall implementations start a new coroutine internally |
| 382 | -- this is used to build complete tracebacks when "coroutine-friendly" pcall | 382 | -- to allow yielding even in Lua 5.1. to allow for accurate |
| 383 | -- is used. | 383 | -- stack traces we keep track of the nested coroutine activations |
| 384 | local pcall_previous = {} | 384 | -- in the weak tables below: |
| 385 | local pcall_callOf = {} | 385 | local weak_meta = { __mode = "kv" } |
| 386 | local xpcall_running = {} | 386 | -- table that maps each running coroutine started by pcall to |
| 387 | -- the coroutine that resumed it (user coroutine *or* pcall | ||
| 388 | -- coroutine!) | ||
| 389 | local pcall_previous = setmetatable({}, weak_meta) | ||
| 390 | -- reverse of `pcall_mainOf`. maps a user coroutine to the | ||
| 391 | -- currently active pcall coroutine started within it | ||
| 392 | local pcall_callOf = setmetatable({}, weak_meta) | ||
| 393 | -- similar to `pcall_mainOf` but is used only while executing | ||
| 394 | -- the error handler of xpcall (thus no nesting is necessary!) | ||
| 395 | local xpcall_running = setmetatable({}, weak_meta) | ||
| 387 | 396 | ||
| 388 | -- handle debug functions | 397 | -- handle debug functions |
| 389 | if type(debug) == "table" then | 398 | if type(debug) == "table" then |
| @@ -660,7 +669,9 @@ if lua_version < "5.3" then | |||
| 660 | return result | 669 | return result |
| 661 | end | 670 | end |
| 662 | 671 | ||
| 663 | local pcall_mainOf = {} | 672 | -- maps the internal pcall coroutines to the user coroutine that |
| 673 | -- *should* be running if pcall didn't use coroutines internally | ||
| 674 | local pcall_mainOf = setmetatable({}, weak_meta) | ||
| 664 | 675 | ||
| 665 | if not is_luajit52 then | 676 | if not is_luajit52 then |
| 666 | function M.coroutine.running() | 677 | function M.coroutine.running() |
