lua-users home
lua-l archive

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

Hi Diego,

> I can see it happening now. I am not sure if the best idea is to use rawget
> in getfield. There might be a use for the __index metamethod in a
> namespace other than exposing the global variables through it. I would
> instead require the writer of mymodule to clear out the __index
> methamethod, so that globals are not visible. It can be done with a line
> such as
>      getmetatable(_M).__index = nil
> in the end of mymodule.lua. Either this, or the writer of mymodule.error
> can do it instead.

I see you point, but I actually think that it's not so unusual that people 
start to create Lua packages composed of different sub-modules (e.g. 
mymod.core and mymod.error) that are loaded by a require 'mymod'. Course, 
you can always deal with odd situations by changing module metatables or 
something like that, but maybe the best thing is focus on most common use. 
Additionally, the rawget does not avoid peculiar semantics at __index for 
module tables, it just avoid its use at package load (what I think is a 
good idea). I don't like that solution at all, but I can live with that if 
that's the way it must be. By the way, the behavior in Lua 5.1 work 6 
seems to differ. It would be nice to unify these package models.

Renato Maia