lua-users home
lua-l archive

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


On Thu, Jun 09, 2011 at 05:57:21PM +0200, Andreas Falkenhahn wrote:
> 
> 
> function myfunc()
> local a, b = 1,2
> end
> 
> and repeat the line "local a, b = 1,2" over 100 times in the function, I get 
> the following error: 
> input:102: function at line 1 has more than 200 local variables
> 
> I'm wondering whether this is intended behaviour because actually, I'm only using
> two variables named 'a' and 'b'. They are all placed in the same scope so I don't
> quite understand why Lua creates 200 variables from these two. Because the 
> initializations occur always in the same scope, Lua wouldn't have to store 200 
> variables on the stack but it could simply work with two. Any explanations for 
> this behaviour?

The code for `local a` does not check whether `a` already exists.
It's the familiar Lua trade-off: speed is more important than being 
foolproof, because Lua programmers by definition are not fools.

Dirk