[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Multiple return values from require()
- From: Duncan Cross <duncan.cross@...>
- Date: Sat, 17 Oct 2009 19:07:16 +0100
On Sat, Oct 17, 2009 at 7:01 PM, Matthias Kluwe <mkluwe@gmail.com> wrote:
> Hi!
>
> 2009/10/17 Linker <linker.m.lin@gmail.com>:
>> You can return a table instead of a list .
>
> Well, I know ... I can return _one_ table, but matrix.lua does return
> two of them, and there has to be a trick (well, not a trick obviously,
> but I can't find it in the reference manual).
>
>> On Sat, Oct 17, 2009 at 19:27, Matthias Kluwe <mkluwe@gmail.com> wrote:
>>>
>>> rtunately, only one of them is returned by require:
>
> Regards,
> Matthias
>
I believe when you require() a module, the single first return value
is what gets stored in the package.loaded table, so the next time
require gets called for the same module you will only ever get that
one value back anyway. You would need to write your own variant of
require() to store the results in a table and unpack them etc. for
what you are talking about to properly work. (Disclaimer, I haven't
actually tried this matrix script, this is just from what I
understand.)
-Duncan