v0.13.7
errors and warnings / types

errors and warnings / types / W2057

W2057 warning

coroutine.yield inside a function passed to pcall/xpcall/a C callback (cannot yield across that boundary in Lua 5.1)

area
types (x2xxx)
fails the build
with --deny-warnings

coroutine.yield inside a function passed straight to pcall, xpcall or a C function that calls it back (a table.sort comparator, a string.gsub callback). In WoW's Lua 5.1 a coroutine can't yield across those, and the yield raises "attempt to yield across metamethod/C-call boundary". Move the yield out of the callback, for example by collecting the work and yielding in the loop around it.

Example

× failswowlua
local co = coroutine.create(function()    pcall(function()        coroutine.yield(1)    end)end)coroutine.resume(co)
✓ compileswowlua
local co = coroutine.create(function()    pcall(function()        print("work")    end)    coroutine.yield(1)end)coroutine.resume(co)

The compiler reports it like this:

warning[W2057]: `coroutine.yield` cannot yield across `pcall` in Lua 5.1
  ┌─ src/main.wowlua:3:9
  │
3 │         coroutine.yield(1)
  │         ^^^^^^^^^^^^^^^^^^ here
codemessage
W8430Job yield call (check/yield/sleep/waitFor) inside pcall/xpcall/securecall*, a metamethod or a C-function callback

Offline

terminal
$ wowlua explain W2057
W2057 (warning): coroutine.yield inside a function passed to pcall/xpcall/a C callback (cannot yield across that boundary in Lua 5.1)

source on GitHub ↗