lua-users home
lua-l archive

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


On Oct 22, 2011, at 8:32 PM, David Manura wrote:

> On Fri, Oct 21, 2011 at 2:49 PM, Sam Roberts <vieuxtech@gmail.com> wrote:
>> Everybody who _REALLY_ thinks having module names
>> [not?] be global, I'd say you should be lobbying for all the
>> standard modules to be removed from the global namespace.
>> I'd be vehemently opposed, of course, but at
>> least you'd be consistent!
> 
> That's a good question.  The way I see it, we have this table called
> "_G".  It contains the standard library, which are functions that
> almost all programs frequently use.  Some rare programs might not use
> any of it.  Many other programs might not use parts like debug.  Some
> sandboxed programs may an alternative table containing a subset of _G
> with some wrapped or reimplemented functions.

For a lot of cases with "real code" (as opposed to configuration files, "scripts", etc) I could see a strong case for saying the only thing that gets supplied is require and you have to use it to get to everything else. Of course, this would mean that all of the top level functions should either move down into standard modules -- e.g., pairs becomes table.pairs -- or they need to be individually required.

This makes writing anything in interactive mode a pain. It makes writing simple scripts a pain. But it also makes code faster because it reduces global lookups (though LuaJIT presumably manages to make those go away as well). If module names were kept simple, it would also argue for an import directive so one could write:

	import io

and have it mean:

	local io = require "io"

Mark