lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


If you have an urgent need, you can try to modify the type of nupvalues to uint

Roberto Ierusalimschy <roberto@inf.puc-rio.br> 于2021年7月13日周二 上午3:30写道:
> PUC Lua 5.4 has a hard limit of 255 upvalues, both for Lua closures and for
> C closures. The comment next to MAXUPVALS in lfunc.c says that this is
> because the index of an upvalue must fit in an 8-bit virtual-machine
> register.
>
> I understand why this would be the case for Lua closures. Many VM
> instructions such as GETUPVAL refer to the upvalue using an 8 bit address.
>
> However, I don't understand why this limit also applies to C closures, the
> ones created via the C API with lua_pushcclosure. Is there some place where
> the number of upvalues of a C closure must fit in 8 bits? Or is this limit
> only to ensure that the limit is similar to the limit for Lua closures?

The number of upvalues in both kinds of closures is stored in a byte
(nupvalues); see ClosureHeader in lobject.h.

-- Roberto