Current section
Files
Jump to
Current section
Files
doc/man/lfescript.1
.\" Automatically generated by Pandoc 2.11.2
.\"
.TH "lfescript" "1" "2013-2016" "" ""
.hy
.SH NAME
.PP
lfescript - Lisp Flavoured Erlang (LFE) scripting support
.SH SYNOPSIS
.PP
lfescript provides support for running short LFE programs without having
to compile them first and an easy way to retrieve the command line
arguments.
.SH EXPORTS
.PP
\f[B]script-name script-arg1 script-arg2 \&...\f[R]
.PP
\f[B]lfescript lfescript-flags script-name script-arg1 script-arg2
\&...\f[R]
.PP
lfescript runs a script written in LFE.
.PP
\f[B]lfescript:script_name() -> File\f[R]
.PP
Types:
.IP
.nf
\f[C]
File = filename()
\f[R]
.fi
.PP
The \f[C]script_name/0\f[R] function returns the name of the lfescript
being executed.
If the function is invoked outside the context of an lfescript, the
behavior is undefined.
.SH EXAMPLE
.PP
Here follows an example script.
.IP
.nf
\f[C]
$ cat factorial
#! /usr/bin/env lfescript
;; -*- mode: lfe -*-
;;! -smp enable -sname factorial -mnesia debug verbose
(defun main
([(list string)]
(try
(let* ((n (list_to_integer string))
(f (fac n)))
(lfe_io:format \[dq]factorial \[ti]w = \[ti]w\[rs]n\[dq] (list n f)))
(catch
((tuple _ _ _) (usage)))))
([_] (usage)))
(defun fac
([0] 1)
([n] (* n (fac (- n 1)))))
(defun usage ()
(lfe_io:format \[dq]usage: factorial integer\[rs]n\[dq] ()))
\f[R]
.fi
.PP
The header of the LFE script is different from a normal LFE module.
The first line is an interpreter line which invokes lfescript if the
script is run as in the first command line above.
If lfescript is explicitly invoked in the second command line above then
this header line will be ignored.
On the second or third line it is possible to give arguments to the
emulator with the syntax:
.IP
.nf
\f[C]
;;! -smp enable -sname factorial -mnesia debug verbose
\f[R]
.fi
.PP
In the example the second line is an optional directive to Emacs which
causes it to enter LFE mode when editing the script file.
.PP
The rest of the file contains LFE source code.
It must always contain the function \f[C]main/1\f[R].
When the script is run this function will be called with a list of
strings representing the arguments with which the script was called.
It is possible to define, include and use macros in the source code.
.PP
The source code is checked and warnings and errors will be printed.
If there are errors the script will not run and it will terminate with
exit status 127.
Otherwise the code will be interpreted.
If the function \f[C]main/1\f[R] returns successfully then the exit
status for the script will be 0 but if an exception is raised then exit
status will be 127.
.SH OPTIONS
.PP
The following option is accepted by lfescript
.IP \[bu] 2
\f[C]-s\f[R] - Only perform a syntactic and semantic check of the script
file.
Warnings and errors (if any) are written to the standard output, but the
script will not be run.
The exit status will be 0 if there were no errors, and 127 otherwise.
.PP
Unrecognised options are ignored.
.SH ENVIRONMENT VARIABLES
.PP
\f[B]LFESCRIPT_EMULATOR\f[R]
.PP
The command used to start the emulator.
Default is `erl'.
This can be useful for passing arguments into the emulator, for example
.IP
.nf
\f[C]
LFESCRIPT_EMULATOR=\[dq]erl -pa sune\[dq]
\f[R]
.fi
.PP
will add the directory sune to the code path.
.SH SEE ALSO
.PP
\f[B]lfe(1)\f[R], \f[B]lfe_guide(7)\f[R]
.SH AUTHORS
Robert Virding.