lua-users home
lua-l archive

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


On Mon, Apr 27, 2015 at 6:54 AM, Egor Skriptunoff
<egor.skriptunoff@gmail.com> wrote:
> On Mon, Apr 27, 2015 at 3:50 PM, Coda Highland <chighland@gmail.com> wrote:
>>
>>
>> local a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a
>> local a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a
>> local a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a
>> local a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a
>> local a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a
>> local a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a
>> local a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a
>> local a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a
>> local a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a
>> local a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a
>>
>> a={{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
>>
>> This will make LuaJIT throw the same error.
>>
>> /s/ Adam
>>
>
> 200 local variables is the limit, so use one less and LuaJIT will NOT throw
> the error.

If you take a local off, you've freed up a stack slot, and you have to
add another set of braces to the table in order to continue to trigger
the error -- my code is a minimal case; I didn't pad it with excess
braces just to make it resilient against people trying to make it
work. ;)

> My code is a simplified version (thus all variables have the same name) of
> real life
> automatically generated script, which has about 160 local vars and some
> number of
> big matrices containing numeric data.
> According to language manual, such code is completely legal.
> If some strange complexity limitations are exist in vanilla Lua
> implementation, they
> must be clearly declared in the manual.
>
> Is Lua really suitable only for short human-written code?
>
> --Egor

Lua is suitable for LONG human-written code, too.

The limits are arbitrary, can be redefined by rebuilding Lua, and are
not part of the language specification because they're an
implementation detail. Dealing with the limits and requirements of the
compiler is something that anyone doing mechanical code generation has
to deal with -- Lua is not unique in this regard. For example, Visual
Studio imposes a 1MB limit on the size of a stack frame, and it's
entirely possible for automatically-generated code to hit this, and
the workaround if you don't want to change how your code works is to
increase that limit with a compiler option. As another example, the
C++ language specification provides a guideline of a limit of 256
levels of nesting and a limit of 1024 local variables.

You've ignored all of my suggestions on how to address the issue. And
because I'm here to help, I'll add one more to the list: If you have
large nested matrices you can also improve the stack behavior by
breaking up the assignment, i.e.,

a = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
a[#a] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
      1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2}

/s/ Adam