Lua Application packager
[!WARNING]
This repository is no longer maintained and has been archived.
Please consider using LuaX instead.
lapp packs Lua scripts together along with a Lua interpretor (Lua 5.4.4) and
produces a standalone executable for Linux and Windows.
lapp runs on Linux and lapp.exe on Windows.
lapp can produce both Linux and Windows binaries.
lapp.exe can produce Windows binaries only.
No Lua interpretor needs to be installed. lapp contains its own interpretor.
lapp also comes with luax which bundles lapp with a Lua REPL.
Compilation
Get lapp sources on GitHub: https://github.com/CDSoft/lapp, download
dependencies and submodules and run make:
$ git clone https://github.com/CDSoft/lapp
$ cd lapp
$ sudo make dep # install make, gcc (musl-gcc), ...
$ make submodules # retreive submodules (luasocket, lz4, ...)
$ make # compile and test
Installation
$ make install # install lapp and luax to ~/.local/bin or ~/bin
$ make install PREFIX=/usr/bin # install lapp and luax to /usr/bin
lapp and luax are single autonomous executables.
They do not need to be installed and can be copied anywhere you want.
make install only install Linux binaries and is not meant to be used on Windows.
Precompiled binaries
It is usually highly recommended to build lapp from sources.
Some precompiled binaries are available here: lapp release.
The Linux and Raspberry Pi binaries are linked statically with
musl and are not dynamic executables. They should
work on any Linux distributions.
Usage
Usage: lapp [-o OUTPUT] script(s)
Options:
-o OUTPUT set the name of the output executable
The main script shall be the first one.
Other scripts are libraries that can be loaded by the main script.
The name of OUTPUT defines the target platform:
OUTPUT.exe produces a Windows binary
OUTPUT.lc produces a portable bytecode (to be run with luax OUTPUT.lc)
OUTPUT produces a Linux executable
Examples
| Host |
Target |
Command |
| Linux |
Linux |
lapp main.lua lib1.lua lib2.lua -o linux_executable |
| Linux |
Windows |
lapp main.lua lib1.lua lib2.lua -o windows_executable.exe |
| Linux |
Bytecode |
lapp main.lua lib1.lua lib2.lua -o bytecode.lc |
| Windows |
Windows |
lapp.exe main.lua lib1.lua lib2.lua -o windows_executable.exe |
| Windows |
Bytecode |
lapp.exe main.lua lib1.lua lib2.lua -o bytecode.lc |
Running linux_executable is equivalent to running luax main.lua.
Running windows_executable.exe is equivalent to running luax.exe main.lua.
Running luax bytecode.lc is equivalent to running luax main.lua or luax.exe main.lua.
Dependencies
Building lapp requires some external softwares.
- wget: to download the Lua sources
- gcc and musl: used to
compile Lua and
lapp for Linux
- MinGW-w64: Linux port of the Windows MinGW
compiler used to compile the Windows version of
lapp.exe
- Wine: used to test the Windows binaries on Linux
- and a decent programming environment on Linux...
Built-in modules
The lapp runtime comes with a few builtin modules.
These modules are heavily inspired by BonaLuna.
"Standard" library
local fun = require "fun"
fun.id(...){.lua} is the identity function.
fun.const(...){.lua} returns a constant function that returns ....
fun.keys(t){.lua} returns a sorted list of keys from the table t.
fun.values(t){.lua} returns a list of values from the table t, in the same order than fun.keys(t){.lua}.
fun.pairs(t){.lua} returns a pairs{.lua} like iterator, in the same order than fun.keys(t){.lua}.
fun.concat(...){.lua} returns a concatenated list from input lists.
fun.merge(...){.lua} returns a merged table from input tables.
fun.flatten(...){.lua} flattens input lists and non list parameters.
fun.replicate(n, x){.lua} returns a list containing n{.lua} times the Lua object x{.lua}.
fun.compose(...){.lua} returns a function that composes input functions.
fun.map(f, xs){.lua} returns the list of f(x){.lua} for all x{.lua} in xs{.lua}.
fun.tmap(f, t){.lua} returns the table of {k = f(t[k])}{.lua} for all k{.lua} in keys(t){.lua}.
fun.filter(p, xs){.lua} returns the list of x{.lua} such that p(x){.lua} is true.
fun.tfilter(p, t){.lua} returns the table of {k = v}{.lua} for all k{.lua} in keys(t) such that p(v){.lua} is true.
fun.foreach(xs, f){.lua} executes f(x){.lua} for all x in xs.
fun.tforeach(t, f){.lua} executes f(t[k]){.lua} for all k{.lua} in keys(t){.lua}.
fun.prefix(pre){.lua} returns a function that adds a prefix pre to a string.
fun.suffix(suf){.lua} returns a function that adds a suffix suf to a string.
fun.range(a, b [, step]){.lua} returns a list of values [a, a+step, ... b]. The default step value is 1.
fun.I(t){.lua} returns a string interpolator that replaces $(...) by
the value of ... in the environment defined by the table t. An interpolator
can be given another table to build a new interpolator with new values.
lapp adds a few functions to the builtin string module:
string.split(s, sep, maxsplit, plain){.lua} splits s using sep as a separator.
If plain is true, the separator is considered as plain text.
maxsplit is the maximum number of separators to find (ie the remaining string is returned unsplit.
This function returns a list of strings.
string.lines(s){.lua} splits s using '\n' as a separator.
string.words(s){.lua} splits s using '%s' as a separator.
string.ltrim(s){.lua}, string.rtrim(s){.lua}, string.trim(s){.lua} remove left/right/both end spaces
fs: File System module
local fs = require "fs"
fs.getcwd(){.lua} returns the current working directory.
fs.chdir(path){.lua} changes the current directory to path.
fs.dir([path]){.lua} returns the list of files and directories in
path (the default path is the current directory).
fs.walk([path], [reverse]){.lua} returns a list listing directory and
file names in path and its subdirectories (the default path is the current
directory). If reverse is true, the list is built in a reverse order
(suitable for recursive directory removal)
fs.mkdir(path){.lua} creates a new directory path.
fs.mkdirs(path){.lua} creates a new directory path and its parent
directories.
fs.rename(old_name, new_name){.lua} renames the file old_name to
new_name.
fs.mv(old_name, new_name){.lua} alias for fs.rename(old_name, new_name){.lua}.
fs.remove(name){.lua} deletes the file name.
fs.rm(name){.lua} alias for fs.remove(name){.lua}.
fs.rmdir(path, [params]){.lua} deletes the directory path{.lua} (recursively if params.recursive{.lua} is true{.lua}.
fs.copy(source_name, target_name){.lua} copies file source_name to
target_name. The attributes and times are preserved.
fs.is_file(name) returns true if name is a file.
fs.is_dir(name) returns true if name is a directory.
fs.stat(name){.lua} reads attributes of the file name. Attributes are:
name: name
type: "file" or "directory"
size: size in bytes
mtime, atime, ctime: modification, access and creation times.
mode: file permissions
uR, uW, uX: user Read/Write/eXecute permissions (Linux only)
gR, gW, gX: group Read/Write/eXecute permissions (Linux only)
oR, oW, oX: other Read/Write/eXecute permissions (Linux only)
aR, aW, aX: anybody Read/Write/eXecute permissions
fs.inode(name){.lua} reads device and inode attributes of the file name.
Attributes are:
dev, ino: device and inode numbers
fs.chmod(name, other_file_name){.lua} sets file name permissions as
file other_file_name (string containing the name of another file).
fs.chmod(name, bit1, ..., bitn){.lua} sets file name permissions as
bit1 or ... or bitn (integers).
fs.touch(name){.lua} sets the access time and the modification time of
file name with the current time.
fs.touch(name, number){.lua} sets the access time and the modification
time of file name with number.
fs.touch(name, other_name){.lua} sets the access time and the
modification time of file name with the times of file other_name.
fs.basename(path){.lua} return the last component of path.
fs.dirname(path){.lua} return all but the last component of path.
fs.absname(path){.lua} return the absolute path name of path.
fs.join(...){.lua} return a path name made of several path components
(separated by fs.sep).
fs.with_tmpfile(f){.lua} calls f(tmp){.lua} where tmp{.lua} is the name of a temporary file.
fs.with_tmpdir(f){.lua} calls f(tmp){.lua} where tmp{.lua} is the name of a temporary directory.
fs.sep{.lua} is the directory separator (/ or \\).
fs.uR, fs.uW, fs.uX{.lua} are the User Read/Write/eXecute mask for
fs.chmod.
fs.gR, fs.gW, fs.gX{.lua} are the Group Read/Write/eXecute mask for
fs.chmod.
fs.oR, fs.oW, fs.oX{.lua} are the Other Read/Write/eXecute mask for
fs.chmod.
fs.aR, fs.aW, fs.aX{.lua} are All Read/Write/eXecute mask for fs.chmod.
mathx: complete math library for Lua
local mathx = require "mathx"
mathx is taken from Libraries and tools for Lua.
This is a complete math library for Lua 5.3 with the functions available
in C99. It can replace the standard Lua math library, except that mathx
deals exclusively with floats.
There is no manual: see the summary below and a C99 reference manual, e.g.
http://en.wikipedia.org/wiki/C_mathematical_functions
mathx library:
acos cosh fmax lgamma remainder
acosh deg fmin log round
asin erf fmod log10 scalbn
asinh erfc frexp log1p sin
atan exp gamma log2 sinh
atan2 exp2 hypot logb sqrt
atanh expm1 isfinite modf tan
cbrt fabs isinf nearbyint tanh
ceil fdim isnan nextafter trunc
copysign floor isnormal pow version
cos fma ldexp rad
imath: arbitrary precision integer and rational arithmetic library
local imath = require "imath"
imath