Module pl.app
Application support functions.
See the Guide
Dependencies: pl.utils , pl.path , lfs
Functions
require_here (base) | add the current script’s path to the Lua module path. |
appfile (file) | return a suitable path for files private to this application. |
platform () | return string indicating operating system. |
parse_args (args, flags_with_values) | parse command-line arguments into flags and parameters. |
Functions
- require_here (base)
-
add the current script’s path to the Lua module path.
Applies to both the source and the binary module paths. It makes it easy for
the main file of a multi-file program to access its modules in the same directory.
base
allows these modules to be put in a specified subdirectory, to allow for cleaner deployment and resolve potential conflicts between a script name and its library directory.Parameters:
base
: optional base directory.
Returns:
-
the current script’s path with a trailing slash
- appfile (file)
-
return a suitable path for files private to this application.
These will look like ‘~/.SNAME/file’, with ‘~’ as with expanduser and
SNAME is the name of the script without .lua extension.
Parameters:
file
: a filename (w/out path)
Returns:
- a full pathname, or nil
- ‘cannot create’ error
- platform ()
-
return string indicating operating system.
Returns:
-
‘Windows’,‘OSX’ or whatever uname returns (e.g. ‘Linux’)
- parse_args (args, flags_with_values)
-
parse command-line arguments into flags and parameters.
Understands GNU-style command-line flags; short (-f) and long (—flag).
These may be given a value with either ‘=’ or ‘:’ (-k:2,—alpha=3.2,-n2);
note that a number value can be given without a space.
Multiple short args can be combined like so: (-abcd).
Parameters:
args
: an array of strings (default is the global ‘arg’)flags_with_values
: any flags that take values, e.g.{out=true}
Returns:
- a table of flags (flag=value pairs)
- an array of parameters
Raises:
if args is nil, then the globalargs
must be available!