Module pl.app

Application support functions.

See the Guide

Dependencies: pl.utils, pl.path

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.
lua () return the full command-line used to invoke this script.
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 string optional base directory.

Returns:

    string 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 string a filename (w/out path)

Returns:

  1. a full pathname, or nil
  2. ‘cannot create’ error
platform ()
return string indicating operating system.

Returns:

    ‘Windows’,‘OSX’ or whatever uname returns (e.g. ‘Linux’)
lua ()
return the full command-line used to invoke this script. Any extra flags occupy slots, so that lua -lpl gives us {[-2]='lua',[-1]='-lpl'}

Returns:

  1. command-line
  2. name of Lua program used
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 {string} an array of strings (default is the global arg)
  • flags_with_values tab any flags that take values, e.g. {out=true}

Returns:

  1. a table of flags (flag=value pairs)
  2. an array of parameters

Raises:

if args is nil, then the global args must be available!
generated by LDoc 1.4.6 Last updated 2017-07-18 16:28:41