[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Local Variables
- From: Tim Hill <drtimhill@...>
- Date: Fri, 8 Aug 2014 17:09:55 -0700
On Aug 8, 2014, at 3:29 PM, Mason Mackaman <masondeanm@aol.com> wrote:
> So why isn’t everything in the standard libraries made local by default if it’s always faster that way?
Because locals are not accessible to libraries (and should not be, that’s what makes them local). A local “foo” is fast because the compiler converts accesses to it into direct references to the Lua stack. Globals are global because in Lua they are names that are resolved at run-time. This makes them accessible across compilation units (and hence libraries), but of course makes access slower as the name must be resolved for each reference.
—Tim