[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How to tell if running script directly?
- From: steve donovan <steve.j.donovan@...>
- Date: Sat, 5 Apr 2014 12:55:47 +0200
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