lua-users home
lua-l archive

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

Have you considered making a 'local state= { ... }' that'd have the values within (as named fields).


27.9.2004 kello 12:22, Adam D. Moss kirjoitti:


I'm encountering this error (lua5.0.2):
luac: linv/linv_game.lua:1115: too many upvalues (limit=32) near `('

It wasn't obvious to me why the function was using >32 upvalues.
After some thought, I realized that of course, every time I make
use of a unique 'local' variable from the chunk's scope in my
function, a new upvalue is created.

But, although this is the first time I've encountered this limit,
the function I get this error within isn't contrived and perhaps
isn't even unusual -- it's a set-up function that restores my
game's essential variables back to a known state.  Thus it's
perfectly reasonable to assume that it'll refer to many, in this
case 33, module-local variables.

I could (and probably will) solve this by increasing MAXUPVALUES,
but I wanted to let the Lua authors know that I encountered this
limit in non-contrived use, and maybe it would be nice to raise
this limit by default.  (I see this is part of luaconf.h in
lua 5.1 -- great.)

I could also solve this by making many of my module's chunk's
variables non-local, but 'local' seems an elegant habit where
it's possible; a 'local' var avoids polluting the module/global
tables, is slightly faster than table-lookups, and has a GC
lifetime more clearly tied to that of its users.

(Let me know if I'm evil for liking locals so much.)