Hi,
On 18.10.2012 19:00, Manuel Kasser wrote:
[...]
>> However, with lua 5.2 module() was deprecated. :-)
> Does that mean that "require" will work without the "module()"-line in
> the required file? And if "module" handles the placing of stuff of foo
> under foo.*, will that mean that this is also vanishing? Or does require
> take over at this point?
The way that require() is supposed to work (and already works in lua 5.1) is
that the last line of the lua file that is being loaded returns a value. This
value is what require() will return.
For example, your module would look like this in this mode:
local widgetfile = {}
function widgetfile.makecpuw()
cputxt = widget({type = "textbox"})
vicious.register(cputxt, vicious.widgets.cpu, '<span color="#9393cc">CPU:
$1%</span>', 1)
return cputxt
end
return widgetfile
The reason why this is better than with "module()" is that this file can be
renamed. With module(), the argument to module decides under which name the
module is registered. With the above approach, the name "widgetfile" has no real
meaning and instead the arguments to register() decide where the module is
loaded to.
However, without module(), the module doesn't get placed into a global variable.
This means you have to do
widgetfile = require("widgetfile")
This is a good thing! This makes it harder for modules to accidentally depend on
other modules (by getting them from the global variable) without properly
require()ing them.
> Finally, I chose the "require"-way for me, because I prefer having the
> functions placed after the name of the file (sort of) they are in for
> better overview over the configuration.
>
> One question concerning that: why does stuff like "local client =
> client" work, more precisely: why is the second "client" accessable as
> the global one before "module", but not after? Is this especially
> designed this way, that in this case lua checks for global variables or
> does it have another reason?
module() replaces the environment (_G) with a new, empty table. You could do the
same directly with _G = {}. This new environment is accessible as _M. Because it
is empty, nothing is accessible.
However, local variables aren't resolved through the environment and thus stay
accessible.
> Again thanks for your help, I think I'm getting into it!
> Manuel
This is the end of today's lua course. Man, I know way too much about lua...
Cheers,
Uli
--
my $key = "\x49\x03\x93\x08\x19\x94\x96\x94\x28\x93\x83\x04\x68\x28\xa8\xf5".
"\x0a\xb9\x94\x02\x45\x81\x93\x1f\xbc\xd7\xf3\xad\x93\xf5\x32\x93";
my $cipher = Crypt::Rijndael->new( $key, Crypt::Rijndael::MODE_ECB() );
my $plain = $ciper->decrypt($daten);
--
To unsubscribe, send mail to [email protected].