Browse Source

A return can have at most 254 values

master
Roberto Ierusalimschy 3 months ago
parent
commit
3e88b72b8e
  1. 2
      lcode.c
  2. 11
      testes/calls.lua

2
lcode.c

@ -208,6 +208,8 @@ void luaK_ret (FuncState *fs, int first, int nret) {
case 1: op = OP_RETURN1; break;
default: op = OP_RETURN; break;
}
if (nret + 1 > MAXARG_B)
luaX_syntaxerror(fs->ls, "too many returns");
luaK_codeABC(fs, op, first, nret + 1, 0);
}

11
testes/calls.lua

@ -518,5 +518,16 @@ do -- check reuse of strings in dumps
end
end
do -- test limit of multiple returns (254 values)
local code = "return 10" .. string.rep(",10", 253)
local res = {assert(load(code))()}
assert(#res == 254 and res[254] == 10)
code = code .. ",10"
local status, msg = load(code)
assert(not status and string.find(msg, "too many returns"))
end
print('OK')
return deep

Loading…
Cancel
Save