v0.13.7
errors and warnings / stdlib

errors and warnings / stdlib / W8430

W8430 warning

Job yield call (check/yield/sleep/waitFor) inside pcall/xpcall/securecall*, a metamethod or a C-function callback

area
stdlib (x8xxx)
fails the build
with --deny-warnings

Inside a function passed to jobs.start, the job's context (ctx:check, ctx:yield, ctx:sleep, ctx:waitFor) is called inside a function literal handed to pcall, xpcall, securecall, securecallfunction, table.sort or gsub, or inside a metamethod (setmetatable(t, { __index = function … end }), mt.__lt = function … end). Jobs are coroutines, and Lua 5.1 cannot yield across these calls: at run time it raises "attempt to yield across metamethod/C-call boundary". Yield before or after the call instead, or split the work so the callback doesn't need to yield.

Example

× failswowlua
import * as jobs from "wowlua:jobs" local items = { 3, 1, 2 }jobs.start(function(ctx)    table.sort(items, function(a, b)        ctx:check()        return a < b    end)end)
✓ compileswowlua
import * as jobs from "wowlua:jobs" local items = { 3, 1, 2 }jobs.start(function(ctx)    ctx:check()    table.sort(items, function(a, b)        return a < b    end)end)

The compiler reports it like this:

warning[W8430]: a job cannot yield here: the coroutine would cross a pcall, a metamethod, or a sort or gsub callback
  ┌─ src/main.wowlua:6:9
  │
6 │         ctx:check()
  │         ^^^^^^^^^^^ yields inside a C call

Offline

terminal
$ wowlua explain W8430
W8430 (warning): Job yield call (check/yield/sleep/waitFor) inside pcall/xpcall/securecall*, a metamethod or a C-function callback

source on GitHub ↗