lua-users home
lua-l archive

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


> On Mon, Dec 6, 2021 at 2:14 PM Victor Bombi <sonoro@telefonica.net> wrote:
> 
> > if ... then print"this is used by require" end
> >
> 
> This fails if there are command-line arguments to the script:
> 
> $ lua -v
> Lua 5.4.3  Copyright (C) 1994-2021 Lua.org, PUC-Rio
> $ cat test.lua
> print(...)
> $ lua test.lua 1 2 3
> 1       2       3

If the module name is fixed, you can make the test a little more
robust as «if (...) == "modname" then ...»  It is not bulletproof,
but it's a reasonable heuristics. You could also try to use the
second argument from 'require', but that seems too much.

-- Roberto