Single static executable, batteries-included, Lua 5.1 interpreter. A fat GopherLua amalgamation of modules in Go and Lua.
Current release: 0.6.0 Gummy Mastiff
+ New module: telegram
+ New module: pushover
+ New module: slack
+ New module: logger
+ New module: fsnotify
+ Converted redis module to object:method style
+ buildah: New NOTIFY settings
0.5.3 Epidural Dollop
+ buildah: Consolidate APK command
0.5.2 Yelling Petunia
+ buildah: Removed default cmd config in ENTRYPOINT()
+ buildah: Removed default arguments from MKDIR(), COPY(), ADD()
0.5.1 Failed Siesta
+ Fix buildah PUSH()
0.5.0 Surplus Siesta
+ New DSL module "buildah"
+ New module "lz4"
+ Selene configuration
+ Removed redundant string.line_to_list()
+ Added string.to_map()
+ Add fourth return value for exec.command
Lua is a good language but no one wants to use it for general-purpose scripting. Complaints are 1-based indexing and missing libraries. The latter is a valid concern. The 5.2+ split also does not help. I was convinced that GopherLua would be a good base for a kitchen-sink interpreter. Writing wrappers for the vast selection of Go packages would be a breeze.
Since GopherLua is an implementation of Lua 5.1, you can use the official Lua 5.1 reference manual: Lua 5.1 Manual. Other resources are also useful just make sure they do not target 5.2+ versions. Search for PDFs of Lua 5.1 cheatsheets. The Learn in in 15 minutes series also has an entry for Lua.
Module | Global | Source | License |
---|---|---|---|
buildah* |
N |
MIT |
|
crypto |
N |
gluacrypto |
MIT |
exec |
Y |
MIT |
|
fmt |
Y |
MIT |
|
fs |
Y |
gopher-lfs |
Unlicense |
fsnotify |
N |
MIT |
|
html |
N |
MIT |
|
http |
N |
gluahttp |
MIT |
inspect |
N |
inspect |
MIT |
json |
N |
gopher-json |
Unlicense |
kapow |
N |
MIT |
|
logger |
N |
MIT |
|
lz4 |
N |
BSD3 |
|
mysql |
N |
gluasql |
MIT |
password |
N |
MIT |
|
pushover |
N |
MIT |
|
redis |
N |
MIT |
|
slack |
N |
MIT |
|
telegram |
N |
MIT |
|
template |
N |
etlua |
MIT |
test |
N |
u-test |
MIT |
uid |
N |
MIT |
[*] DSL module
ℹ️
|
If it says N in the Global field, you need to |
ℹ️
|
Check the |
Tests are in the tests
directory. We are using u-test
. Within the test code is the documentation in AsciiDoc. Generated docs are in the docs
directory. Check the scripts/docs
directory for the command line to generate the docs.
Besides general purpose scripting, a more specific use for me right now is using Lua for writing web apps. You can write it dynamic style like PHP but instead you have Lua. Another idea is hooking Go packages that interface with DevOps things. Instead of YAML you can program DevOps tools in Lua.
Check this diff to get a feel of the conversion from a shell script to Lua.
Using metatables you can hide the plumbing and present a declarative interface. The following snippet can be found under the scripts
directory. It is used to run the MariaDB container under systemd for testing the in-tree mysql
module.
require('podman'){ NAME = 'mariadb'; URL = 'docker://docker.io/library/mariadb'; TAG = '10.5'; CPUS = '1'; UNIT = require 'systemd.mariadb'; DIR = '/srv/podman/mariadb'; always_update = false; overwrite_password = false; }
Tests |
152/152 |
Static executable bytes |
8744960 |
Compiling-in modules into LadyLua adds a bit to startup time. Compares vanilla GopherLua glua interpreter and current LadyLua ll interpreter.
GopherLua |
313.073µs |
LadyLua |
18.061141ms |
Modules that adds significant bloat to the interpreter. If you don’t need these maybe you can trim them from your fork. Just estimates though. The later added modules may have dependencies shared with earlier modules.
http |
3-4MiB |
redis |
800KiB |
mysql |
500KiB |
slack |
230KiB |
Wonder how it compares to PUC-Rio Lua 5.1.5 and LuaJIT2?
Here’s a benchmark for object access time. Check the bench/
directory for the code. The results are from the default 100M runs. GopherLua is fast enough for unconvoluted work. It also demonstrates that LuaJIT is too smart for these benchmarks.
72.804599166 |
Standard (solid) |
85.15575082900001 |
Standard (metatable) |
76.84095142800001 |
Object using closures (PiL 16.4) |
56.77138606499997 |
Object using closures (noself) |
54.96075333699997 |
Direct Access |
32.508254155999964 |
Local Variable |
12.906285 |
Standard (solid) |
13.649843 |
Standard (metatable) |
13.294447 |
Object using closures (PiL 16.4) |
9.024326 |
Object using closures (noself) |
5.618169 |
Direct Access |
1.76135 |
Local Variable |
0.200721 |
Standard (solid) |
0.200649 |
Standard (metatable) |
0.200672 |
Object using closures (PiL 16.4) |
0.200635 |
Object using closures (noself) |
0.200627 |
Direct Access |
0.200628 |
Local Variable |
Before you go disabling function inlining to reduce the executable size; here are the benchmarks for it.
97.82842299 |
Standard (solid) |
117.51864293899999 |
Standard (metatable) |
103.283447037 |
Object using closures (PiL 16.4) |
66.51865570900003 |
Object using closures (noself) |
69.64288394199997 |
Direct Access |
37.33177725300004 |
Local Variable |