lua-users home
lua-l archive

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


On Mar 01, 2003 at 12:03 +0100, Martin Spernau wrote:
> 
> > I just saw the recent posts on LuaCheia about "setglobals() and
> > C-Functions" -- the Import solution is clearly superior to allowing C
> > modules to write the global namespace.
> > http://www.lua.org/notes/ltn011.html
> >
> > Import provides a table to the module where the module puts its
> > bindings. So, the users can put the bindings in whatever
> > "packages" they want, including temporary/local ones.

[Apologies if I'm repeating old stuff here.]

In a nutshell, the objection I have to these gymnastics is that they
don't solve the underlying problem, which is in order to avoid name
clashes, modules need globally unique names.  When you say:

	import "a"

The "a" needs to uniquely specify the desired module.  If someone else
in the world implements a different module named "a", you still have a
name clash, regardless of whether you can put the results of import()
in an arbitrary table.  In my opinion, it is much simpler to just
adopt the convention that:

	import "a.b.c"

puts its public interface in the global table a.b.c, and then try to
impose some organization on module names.  If the user wants to alias
it, they do:

	local_alias = a.b.c

No muss, no fuss.

-- 
Thatcher Ulrich
http://tulrich.com