diff options
Diffstat (limited to 'compat53.lua')
| -rw-r--r-- | compat53.lua | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/compat53.lua b/compat53.lua index 84ef101..919ab33 100644 --- a/compat53.lua +++ b/compat53.lua | |||
| @@ -328,12 +328,21 @@ if lua_version < "5.3" then | |||
| 328 | #setmetatable({}, { __len = function() return 1 end }) == 1 | 328 | #setmetatable({}, { __len = function() return 1 end }) == 1 |
| 329 | 329 | ||
| 330 | 330 | ||
| 331 | -- table that maps each running coroutine to the coroutine that resumed it | 331 | -- the (x)pcall implementations start a new coroutine internally |
| 332 | -- this is used to build complete tracebacks when "coroutine-friendly" pcall | 332 | -- to allow yielding even in Lua 5.1. to allow for accurate |
| 333 | -- is used. | 333 | -- stack traces we keep track of the nested coroutine activations |
| 334 | local pcall_previous = {} | 334 | -- in the weak tables below: |
| 335 | local pcall_callOf = {} | 335 | local weak_meta = { __mode = "kv" } |
| 336 | local xpcall_running = {} | 336 | -- table that maps each running coroutine started by pcall to |
| 337 | -- the coroutine that resumed it (user coroutine *or* pcall | ||
| 338 | -- coroutine!) | ||
| 339 | local pcall_previous = setmetatable({}, weak_meta) | ||
| 340 | -- reverse of `pcall_mainOf`. maps a user coroutine to the | ||
| 341 | -- currently active pcall coroutine started within it | ||
| 342 | local pcall_callOf = setmetatable({}, weak_meta) | ||
| 343 | -- similar to `pcall_mainOf` but is used only while executing | ||
| 344 | -- the error handler of xpcall (thus no nesting is necessary!) | ||
| 345 | local xpcall_running = setmetatable({}, weak_meta) | ||
| 337 | local coroutine_running = coroutine.running | 346 | local coroutine_running = coroutine.running |
| 338 | 347 | ||
| 339 | -- handle debug functions | 348 | -- handle debug functions |
| @@ -618,7 +627,9 @@ if lua_version < "5.3" then | |||
| 618 | return result | 627 | return result |
| 619 | end | 628 | end |
| 620 | 629 | ||
| 621 | local pcall_mainOf = {} | 630 | -- maps the internal pcall coroutines to the user coroutine that |
| 631 | -- *should* be running if pcall didn't use coroutines internally | ||
| 632 | local pcall_mainOf = setmetatable({}, weak_meta) | ||
| 622 | 633 | ||
| 623 | if not is_luajit52 then | 634 | if not is_luajit52 then |
| 624 | function coroutine.running() | 635 | function coroutine.running() |
