lua-users home
lua-l archive

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


At one time I had spent much thought on implementing modules in Lua.  I
considered the necessity of using upvalues for local module access
intolerable.  It's messy to have to think about if you need the '%' or not
every time you use the name 'Public' or 'Private' in the module definition.
However I think Roberto's method is the best we can do for now.  Someday if
we could replace upvalues with more general lexical scoping this issue would
be resolved.

I was also trying to solve the problem of clashes between the global module
names themselves, and between module names and user program names.
Extending the method Roberto outlined it would be possible for a module,
instead of declaring a global, to pass its local public table as a return
value of the chunk.  The module user is then free to assign that variable to
some other name, local or global.  If the module user choses a local name,
he will have to access the module using upvalue syntax (when inside function
scope) also.

-John