lua-users home
lua-l archive

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


On 5/06/2013, at 6:34 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:

> In that case there is a quick answer to the FAQ:
> 
>    Can a program tell whether it is being run from the command line
>    or from a script?
> 
> if (arg==nil) print
>   "Running from the command line, unless you are trying to fool me."

I think I understand the opposite of your definition of "running from the command line" but that's not the point.
The point is the last time I tried to work out if a module was required or "lua module.lua"ed I think I used debug.getinfo, but you seem to be right...

test.lua:
print("arg:", arg)
print("...:", ...)


$ lua test.lua
arg:	table: 0x7f8b93409320
...:
$ lua
Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> require("test")
arg:	nil
...:	test
> dofile("test.lua")
arg:	nil
...: