runlua: Portable Lua Invocation for POSIX

description

runlua is a POSIX shell script for locating and invoking specific Lua interpreter versions. For example, the environment's Lua 5.1 interpreter might be named lua, lua5.1, lua51, luajit, luajit2.0.2, etc. runlua automates this difficult task in a safe, portable manner. runlua is regularly tested on Linux, OS X, Solaris, AIX, FreeBSD, NetBSD, and OpenBSD. And runlua safely handles all special characters encountered in option arguments, directory and command paths, and shell variables.

To execute a simple statement in either a Lua 5.2 or 5.3 interpreter:


   runlua -r5.2-5.3 -e "print(_VERSION)"

The command-line options to runlua are a superset of the standard Lua interpreter. Run `runlua -h` for a description of each option.

Shebang (#!) Execution

In addition to explicit invocation, runlua supports two modes of shebang execution:


   #!/path/to/runlua -r5.2
   print"running Lua code!"

and


   #!/bin/sh
   echo "running shell code!"
   exec runlua -r5.2 -s"^exec" "$0" "$@"
   print "running Lua code!"

Only Linux and OS X support the first mode. The second is portable in practice--although POSIX does not require sh to be located at /bin/sh, it nonetheless can be invoked from that location on all the environments I've tested.

Also, the first mode requires a fully qualified path name, whereas with the second mode the shell code in the header can locate runlua dynamically. For example, a regression or example script in a project repository might have a header like


   #!/bin/sh
   PATH="${PATH}:$(dirname "$0")/../bin"
   exec "$(dirname "$0")/../contrib/runlua" -s"^exec" "$0" "$@"
   local mymodule = require"mymodule"
   -- ...

which will work regardless of the current working directory when invoking the script.

news

2015-01-22

Initial release.

usage

Run `runlua -h` for detailed usage information.

license

Copyright (c) 2015 William Ahern

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

source

runlua is versioned along with a similar script, luapath, used for compilation of Lua C modules.

git clone http://25thandClement.com/~william/projects/luapath.git

download

runlua-20150122

other projects

airctl | bsdauth | cnippets | libarena | libevnet | authldap | streamlocal | libnostd | zoned | dns.c | delegate.c | llrb.h | lpegk | json.c | cqueues | siphash.h | hexdump.c | timeout.c | luapath | luaossl | lunix | phf | runlua | autoguess | tarsum | prosody-openbsd | AnonNet