[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Command line library load in Lua 5.2
- From: Matthew Wild <mwild1@...>
- Date: Thu, 3 Nov 2011 10:13:14 +0000
On 3 November 2011 09:45, Dirk Laurie <dirk.laurie@gmail.com> wrote:
>>> I.e. the global name is not created by the module, but by the Lua5.2
>>> standalone interpreter.
>>
>> Option '-l' would be essentially useless if it did not create the
>> global. It is intended to be used in interative mode and with the -e
>> option: $ lua5.2 -l mymod -e "print(mymod.foo(10))"
>
> I'll grant that the global is useful in that context.
>
> But '-l' is not useless without the global. Lua 5.1 does not set it.
> Yet nothing forces you to use only modules that set globals 5.1-style.
> It's perfectly OK to use modules that return tables 5.2-style. Just
> say `local mymod=require "mymod"`. This works nicely with '-l',
> because:
>
> * option `-l` adds an item to package.loaded
> * `local mymod = require "mymod"` in the program picks up the module
> loaded with `-l` instead invoking the package search mechanism.
>
I'm confused... if you're going to use require(), that also sets
package.loaded if not already set. So... how is -l useful if you have
to call require right after anyway?
Regards,
Matthew