lua-users home
lua-l archive

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


2018-02-24 13:37 GMT+02:00 albertmcchan <albertmcchan@yahoo.com>:
> On Feb 24, 2018, at 6:30 AM, Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> wrote:
>
>>>        if ... then
>>>          print("I was included as a module")
>>>          return {}
>>>        end
>>>        print("I was executed as a program")
>>
>> Try lua mod.lua 1 2 3 .
>>
>
> As long as the command is NOT mod.lua mod 1 2 3,
> I can test for required with select(1, ...) == 'mod', or simply (...) = "mod"
>
> see http://lua-users.org/wiki/FloatSumFast

Actually, the manual documents what 'require' does, in particular:

"Once a loader is found, require calls the loader with two arguments:
modname and an extra value dependent on how it got the loader. (If the
loader came from a file, this extra value is the file name.)"

And dofile does not do that.

Thanks.

-- Dirk