lua-users home
lua-l archive

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


On Sat, Apr 5, 2014 at 12:16 PM,  <tonyp@acm.org> wrote:
> where _MAIN would be true if the script is run directly, and false if it is
> part of require or dofile.

It's easy to detect if a module has been launched directly. arg[0] has
the name of the script, so

-- mod.lua
print 'always called'

if arg[0]:match 'mod.%.lua$' then
    print 'called directly!'
end

does what's expected