[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Local Variables
- From: Roberto Ierusalimschy <roberto@...>
- Date: Thu, 7 Aug 2014 14:06:19 -0300
> So recently I found out that local variables are always faster. So I
> have two questions, when would you ever need a global variable, and
> why would Lua make all variables global by default if you use local
> way more often? It seems to me that I could just declare a variable
> local right off the bat so it has the same scope as if it were global
> (I feel like there has to be a difference in scope that I just don’t
> know about).
1) Local by default is a mess.
2) You do use a lot of globals in Lua. If you write
print(string.len(str)) --<< 'str' is a local variable
you are using two globals and one local.
-- Roberto