[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How to tell if running script directly?
- From: <tonyp@...>
- Date: Sat, 5 Apr 2014 21:43:30 +0300
Seems like a great solution!!! Thanks. (I tried it and it works fine in
every case. I also tried it with redirection, no problem.)
It also has the right 'mentality' for the latest Lua way of handling
modules.
From: Kevin Martin
Sent: Saturday, April 05, 2014 6:56 PM
To: tonyp@acm.org
Subject: Fwd: How to tell if running script directly?
Hi,
Sent this into list hours ago, but hasn't appeared yet? See my solution
below
Thanks,
Kev
Begin forwarded message:
From: Kevin Martin <kev82@khn.org.uk>
Subject: Re: How to tell if running script directly?
Date: 5 April 2014 12:39:30 BST
To: Lua mailing list <lua-l@lists.lua.org>
On 5 Apr 2014, at 12:32, <tonyp@acm.org> wrote:
I think a better solution is needed.
(This is 5.2, don't know 5.1 situation)
If some code is called through require, then the chunk has the name given
to require as it's first argument, if executed, there are no arguments to
the chunk.
So, for testing, I do
local requirename = …
if requirename then
return moduletable
end
--tests go here
Thanks,
Kev