v0.13.7
errors and warnings / codegen

errors and warnings / codegen / E5001

E5001 error

Lua 5.1 limit exceeded (locals, upvalues, registers, constants, syntax levels, jump distance), including generated locals

area
codegen (x5xxx)
fails the build
yes

The code goes past one of Lua 5.1's fixed limits: at most 200 locals in one function (the file's main chunk counts as one), 60 upvalues per function, 250 registers, 200 nested blocks and subexpressions, and a bounded number of constants and jump distance. WoW would refuse to load such a file, so this stays an error even in a plain Lua file. wowlua compiles every output file with Lua 5.1 to find these, and counts the locals the compiler adds (imports, hoisted declarations) as well.

Split the function, or keep related values in a table instead of separate locals. The upvalue limit often comes from a function that uses many top-level locals of its file: below, show captures 61 of them.

Example

× failswowlua
local v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20,      v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40,      v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60,      v61local function show()    print(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20,        v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40,        v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60,        v61)endshow()
✓ compileswowlua
local values = {}for i = 1, 61 do    values[i] = iendlocal function show()    print(unpack(values))endshow()

The compiler reports it like this:

error[E5001]: Lua 5.1 limit exceeded: function at line 5 has more than 60 upvalues
  ┌─ src/main.wowlua:9:1
  │
9 │         v61)
  │ ^^^^^^^^^^^^ in the function containing this line
  │
  = help: split the function or move locals into a table

Offline

terminal
$ wowlua explain E5001
E5001 (error): Lua 5.1 limit exceeded (locals, upvalues, registers, constants, syntax levels, jump distance), including generated locals

source on GitHub ↗