lua-users home
lua-l archive

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


However, why there are so many upvalues in your design, can you optimize the design? Or putthem into a table

Hugo Musso Gualandi <hgualandi@inf.puc-rio.br> 于2021年7月13日周二 上午2:48写道:
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?

-- Hugo