lua-users home
lua-l archive

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


James Graves wrote:
On Fri, Apr 30, 2010 at 09:58:56AM +0200, steve donovan wrote:
On Fri, Apr 30, 2010 at 8:09 AM, Stuart P. Bentley wrote:
If your script is run in the same place as the application, I've heard
Windows replaces ! or !! with the path up to the running executable.
On Unix, typically you write your Lua script like so and make it executable:

-- ltest
#!/usr/local/bin/lua
print('I am '..arg[0])

And you get exactly what you need from arg[0]

~$ ltest
I am /home/sdonovan/bin/ltest

I promote the use of this for Unix shell script invocation:

    #!/usr/bin/env lua
    print('I am '..arg[0])

This way, it will find whichever lua is first in your execution path,
and run that.  Other people running your script, which may have their
own version of Lua, will be using theirs instead.  And people who
don't have their own copy of Lua will use the system one at
/usr/bin/lua .

Another 1cent. Lorenzo might be considering the building of self-contained scripted applications, in which case the use of shell scripts might or might not be so appropriate.

In any case arg[0] may not work as we want when fiddling with symbolically-linked executables in the style of busybox, I think arg[0] gives the symlink name. So we'd need to make a call to get the path linked to the symlink or check with /proc/self, which is not portable.

--
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia