1

Hi~ I need some helps as i couldn't understand c closures in lua reference manual. As follows:

2)

void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);
...
The maximum value for n is 255.
...

1)

Any access to lua_upvalueindex(n), where n is greater than the number of upvalues of the current function (but not greater than 256, which is one plus the maximum number of upvalues in a closure), produces an acceptable but invalid index.

Both 1) and 2) are descriptions in Lua reference manual. And I am puzzled:

Why can the argument n of lua_upvalueindex be 256 when the maximum number of upvalues is 255?

Could anybody help me?

DarkWiiPlayer
  • 6,871
  • 3
  • 23
  • 38
Licai Liu
  • 11
  • 3
  • Probably, number of upvalues must fit in a byte? That's why `n` <= 255. And index `256` might be reserved just in case you want to create acceptable but invalid index (such index would mean "no upvalue"). – Egor Skriptunoff Sep 12 '19 at 08:40

0 Answers0