lua-users home
lua-l archive

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


Hi Diego,

> I guess the most common use is for a developer of a given module to
> write his own submodules, or at least realize that someone else might do
> it.  At any rate, the getmetatable solution I suggested can be
> implemented by either.

True, but that wasn't exactly what I was talking about.
 
> Besides, the fact that this __index field is left behind is an unwanted
> artifact. I trully believe it should be removed even if you don't plan
> to use "mymodule.error" or the like.  After all, the line
> 
>     c = socket.socket.socket.socket.socket.tcp()
> 
> is ridiculous. :)

It would be really great to overcome this, but I'm afraid that I must have 
missed something. Do you propose to set __index of module metatable to 
nil? Won't this avoid the access to global variables by module functions? 
What I mean is that the following doesn't work:

Lua 5.0.2  Copyright (C) 1994-2004 Tecgraf, PUC-Rio
> module "hello" function sayit() print "Hello World!" end
> getmetatable(hello).__index = nil
> hello.sayit()
stdin:1: attempt to call global 'print' (a nil value)
stack traceback:
        stdin:1: in function 'sayit'
        stdin:1: in main chunk
        [C]: ?

Additionally, in the case that the module writer decides to change the 
__index for the module like you suggested earlier, if I set it to nil then 
the particular semantics previously defined by __index won't work anymore 
in any situation. So why bother to use rawset only at the module loading 
scenario?

> We definitely want to unify Compat-5.1 with Lua 5.1. We are trying to
> keep up with the work releases and will update to Compat-5.1 release 4
> pretty soon. What is that is different between release 3 and work6
> that is bothering you? I haven taken a close look yet.

One thing is that the code below works just like I expected it to do.

Lua 5.1 (work6)  Copyright (C) 1994-2005 Tecgraf, PUC-Rio
> module "mymod" function op() print "I'm mymod.op" end
> module "mymod.error" function op() print "I'm mymod.error.op" end
> mymod.op()
I'm mymod.op
> mymod.error.op()
I'm mymod.error.op
>

Another little silly difference is the base module for Lua basic 
functions. These little differences may not cause many problems now, but 
some developers may be a little disappointed if they find out that their 
Lua-5.0.2+Compat-5.1 compliant modules does not fit properly to the 
package model in Lua 5.1. At least, I did! :o)

Best regards,

Renato Maia.