lua-users home
lua-l archive

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


>> I was seriously contemplating re-implementing my class system in terms
>> of the module function, but this global namespace pollution is a
>> show-stopper :(
>>
>> Any reason(s) for 'module' littering the global environment?

>Probably because this is what modules are for:
>
>C: #include <math.h>
>C++: #include <cmath>
>Java: import java.lang.Math;
>Python: import math

I don't know about other languages, but in python it is very common to use

import x as y

and also

from x import y

or even

from x import y as z

Although each of these polute the global namespace, you can choose the
name of the variable if you wish so.
(there is also the function __import__ that doesn't bind any variable,
just returns the module; it is probably used just in hacks)
The lua5.1 module system (if I understand it at all:) doesn't give you
any freedom for the choice of the name.
Coming from python I find it restrictive (maybe just because I still
think too much python when using lua, which is of course wrong). So I
would also like to know the reason why this approach to modules was
taken in lua - just to understand lua a bit better.

P.