lua-users home
lua-l archive

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


> But I don't understand why Lua is summing
> (number of local variables) + (height of matrix) + (width of matrix)
> Is this sum always limited by MAXSTACK (which is 250 by default) ?
> Does it mean that a matrix 200x200 is impossible?
> 
> Can you give a clear definition of strange limitation I've stumbled upon?

The limitation you got is the number of "registers" used by the code.

- each local uses one register;
- each temporary uses one register (e.g., "a + b * c" may need three
registers to compute, but "a + b + c" needs only two, because it
means "(a + b) + c").
- Lists in tables is a little more complicated: to avoid one opcode
for each value, Lua groups together up to 50 values and set them all
together in one opcode. That means that linear list constructors can
use up to 50 registers. (And the table being built also uses one extra
slot...)

When you write multi-dimensional constructors, all that adds up. When
building the 50-th element, there are already 49 elements in the stack;
on top of that, it needs more 50 registers to build that 50-th element
(which is an array with many elements).  Roughly, you have to count 50
for each dimension (if that dimension has at least 50 elements).

-- Roberto