lua-users home
lua-l archive

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


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.