lua-users home
lua-l archive

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


On Fri, Mar 28, 2008 at 4:36 PM, Michael Elliott <melliott42@yahoo.com> wrote:
>
>  How can I programmatically determine what the current
>  script is that is executing from within the script
>  itself?
>
>  In a Bourne shell script for example I would commonly
>  use something like: SCRIPTNAME=`basename`

Assuming you are running it from the commandline, arg[0] will contain
the name of the script, while the negative arguments will contain how
it was executed.  For example:

$ echo "print(arg[-1], arg[0])" > /tmp/foo.lua && /usr/local/bin/lua
/tmp/foo.lua
/usr/local/bin/lua       /tmp/foo/lua

- Jim