lua-users home
lua-l archive

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


> -----Original Message-----
> From: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org] On
> Behalf Of Rena
> Sent: zondag 3 maart 2013 23:36
> To: Lua mailing list
> Subject: Installing and locating scripts
> 
> So, I've been developing some small applications in Lua, and one issue
> that's come to light is once my app is installed, if it's made up of more
> than one script, the main 'executable' script needs to know where to find
> the other scripts.
> It's enough to use os.getenv('PWD') .. arg[0] during testing, but that
> won't work if the script is in the $PATH. Unfortunately my understanding
> is there's no standard way to determine the current path of the
> executable.
> 
> I'm also not sure what is the best practice when it comes to installing a
> program that consists of several files (the main executable and several
> sub-scripts it includes) on a Linux system.
> With a compiled language you can split your source code into as many files
> as you like and still produce a single compiled binary, but with Lua all
> those individual files *are* your "binary".
> 
> Should I just install the main script in the usual place (/usr/local/bin
> or /usr/bin), the additional scripts in some other standard place
> (/usr[/local]/share/appname/?), and have it try to find them in those
> standard places? Or is there a better way to handle this?
> 
> --
> Sent from my Game Boy.

The exact location is probably system dependent, question is whether you want a self-contained approach or mix with the global lua environment on a system.

My solutions so far (using windows);
1) I mostly have the secondary files written as modules, and installed in the Lua path (LuaRocks). Drawback is that single-use-application-specific modules end up in the general path.
2) Use a bootstrap script that does the locating and only then starts the Lua script (see busted (https://github.com/Olivine-Labs/busted/tree/master/bin ), contains scripts both for windows and *nix). If the script can detect current directory and executable directory, then it's easy to extend the lua path variables to those locations by prefixing them. So you can have the modules located relative to the main script, instead of in the general Lua path (a more self-contained solution)
3) use some tools to wrap the multitude of scripts into a single script.

Thijs