Lua Programming Language
Created:
Learn
- Programming in Lua – class notes.
- Lua - good, bad and ugly parts
- Lua 5.1.4 Annotated Source
- https://www.luafaq.org/
Lua associated languages
Pallene + Lua. Paper .Found via janet lang’s gitter channel. It is a “Friendly Fork” of Titan Language. Pallene is a moon of saturn?
Terra – low level lua like language.
teal; The compiler for Teal, a typed dialect of Lua
Luau is a fast, small, safe, gradually typed embeddable scripting language derived from Lua.
Links and references
- Lua.Space – lua community blog; started Dec 2015.
- What’s different about Lua
- Is Lua interesting, from a programming language design perspective?
- Lua date manipulation
- Lua - world’s most infuriating language.
- How to lua and c - a short novel
- lua’s nil
- Lua links by Tao of Mac
Cool Lua stuff
- Performance counter access with inline assembler in Lua
- Luvi
A project in-between luv and luvit. The goal of this is to make building
luvit and derivatives much easier. Luvi has a somewhat unique, but very
easy workflow for creating self-contained binaries on systems that don’t
have a compiler:
- Using luvi to ship binaries
- Holy build box
- lit - Toolkit for developing, sharing, and running luvit/lua programs and libraries.
- example
of luvit code - IRC activity bot by
technomancy
.
- Fengari is the Lua VM written in JavaScript. It uses JavaScript’s garbage collector so that interoperability with the DOM is non-leaky.
- The Fennel programming language . note.
- bakpakin/moonmint: A Web Framework for Lua
- Urn: A Lisp implementation for Lua | Urn
- rxi/lume: Lua functions geared towards gamedev – “lua’s missing standard library” according to @technomancy
- rochus-keller/LjTools: LuaJIT 2.0 bytecode parser, viewer, assembler and test VM
- I build Lua programs in prod. I use fennel or moonscript as the frontend, and ev… | Hacker News; Dec 2019.
2020-06-04 oasislinux/oasis: a small statically-linked linux system; uses lua for setup, building, package spec etc.,
Mako Server This tiny,
ready-to-run application server packs a punch with its super compact and
efficient Lua web framework and its non-blocking asynchronous sockets.
Plus, it comes with everything you need built-in, including an
integrated database, SMTP, HTTP client/server, and even IoT protocols
like MQTT and industrial protocols like OPC-UA and Modbus.
People
- Calvin Rose – bakpakin.com (creator of Fennel lang, moonmint web framework, etc.,)
- Stefano
Trettel –
moon*
libs for graphics, etc.,
Compiling Lua source files
Let’s say you have a lua program – hello.lua
.
print("Hello Lua!")
The source code can be compiled into a binary file using
luac
$ luac -o hello.luac hello.lua
The file hello.luac can then be used in place of the source file. Using the binary file has some advantages like: faster loading, simple source hiding etc.,
To run a .luac
file (this is my own convention, the Lua
docs do not seem to prefer any particular suffix for the compiled file),
you still need to call the lua interpreter,
$ lua hello.luac
Creating standalone executables for lua
A Lua source file can be converted into a executable using different
methods. srlua
appears to be the popular one.
Download srlua
from here and build it
using make
. Copy glue
and srlua
files into a convenient location, say ~/bin
.
You can now create standalone executable from the Lua source file
–hello.lua
thus:
$ ~/bin/glue ~/bin/srlua hello.lua hello
$ chmod +x hello
$ ./hello
Hello Lua!
Installing new software packages
Luarocks is the deployment and package management system for Lua. Think CPAN for Perl and PyPI for Python.
I have installed Lua in my $HOME
directory. That is,
lua
interpreter resides in $HOME/bin
, include
files in $HOME/include
etc.,
So, to install Luarocks:
$ export PREFIX=$HOME
$ ./configure --prefix=$PREFIX --sysconfdir=$PREFIX/luarocks --force-config
Installing new lua packages is as simple as:
$ cd
luarocks install luasocket
where luasocket
is a new package that is fetched from
the luarocks mirrors and installed.
To make this package available to the Lua interpreter export
LUA_PATH
thusly:
export LUA_PATH="/opt/local/share/lua/5.1//?.lua;/opt/local/lib/luarocks/?.lua;;"
Another LUA_PATH
that makes more sense:
?;?.lua;/usr/local/lua/?/?.lua
Also, to explicitly add paths to a script:
# cat t_paths.lua
package.path = package.path.. ";/opt/local/share/lua/5.1/?.lua"
package.cpath = package.cpath.. ";/opt/local/lib/lua/5.1/?.so"
local s = require "socket"
print(s._VERSION)
Incidentally, on the day I was learning aobut luarocks
,
luaforge.net, the main lua modules repository was down. Friendly folks
on the #lua
IRC channel told me to add mirrors to the
luarocks configuration.
$ vim ~/luarocks/config.lua
I replaced the luaforge.net line with
http://www.luarocks.org/repositories/rocks/",
Misc. Notes
Setting up LUA_PATH
and LUA_CPATH
is always
more complicated than it needs to be. Remember not to have any spaces
after the path seperator ;
.
LuaDist appears promising to set up
virtualenv
like sandboxed environments (and more..) for
lua.
Lua application packaging
luastatic README tells us that it can package lua applications into executables for windows, macos & linux. A few applications that use luastatic to do their packaging are given. It will be nice to find build setups which can compile to all the three OSes using github CI pipeline.
–
See also: Luarocks.