[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Local Variables
- From: William Ahern <william@...>
- Date: Fri, 8 Aug 2014 17:13:39 -0700
On Fri, Aug 08, 2014 at 05:29:18PM -0500, Mason Mackaman wrote:
> So why isn?t everything in the standard libraries made local by default if
> it?s always faster that way?
Other than the implementation for "print" (which gets the global
"tostring"), the standard library is written entirely in C and doesn't do
global lookups.
But one reason not to copy globals into locals is because then other code
can't interpose that function.
For example, in my cqueues project I provide a yieldable implementation of
tostring. Applications can choose to make this yieldable implementation
global by doing
_G.tostring = require"cqueues.auxlib".tostring
However, any module loaded before that line executes and which copies the
tostring function to a local will never see or use the yieldable version.