lua-users home
lua-l archive

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


On Thu, Aug 7, 2014 at 9:56 AM, Mason Mackaman <masondeanm@aol.com> wrote:
> 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).

Global variables are global. :P I mean, seriously, that's the whole
point. They're shared across modules and across functions. (Local
variables aren't inherited when you require another file.)

But you're exactly right -- you could do that, and many people DO
exactly that as an optimization.

/s/ Adam