Getting Started
lrc
can be installed using the LuaRocks package manager:
# installs lrc into the bin directory of your luarocks tree
> luarocks install lrc
Let’s try the freshly installed lrc
command. If you haven’t added your rocks tree to the system PATH you can run eval $(luarocks path)
in your .bashrc
or call ~/.luarocks/bin/lrc
directly.
Compiling your first program using lrc
Create a lua file for your entrypoint.
-- ./main.lua
print "Hello, from lrc!"
Next, invoke lrc to compile your program by specifying your entrypoint:
-o main
is optional here, the executable name would otherwise be derived from the filename of the entrypoint. Now you can run it via:
> lrc main.lua -o main
Note Arch Linux does not package static libraries. To install
liblua.a
via luarocks, see Troubleshooting.
> ./main
Hello, from lrc!
Using luarocks to build your project
Create a new rockspec by running luarocks write_rockspec
and adjust its build
section as shown below:
On luarocks 3.10.0+ this will automaticially install the lrocket build plugin for luarocks. If you’re running an earlier version of luarocks, you can install the build system manually by running
luarocks install luarocks-build-lrocket
.
build = {
type = "lrocket",
entrypoint = "main.lua",
output = "bin/main"
}
Now you can build and install your program using luarocks make
. For building only, append --no-install
:
> luarocks make
You should now be able to run your executable:
> bin/main
Hello, from lrc!
> main # from system PATH
Hello, from lrc!
To learn more about the available compiler options, feel free to check out the lrc usage page. For some examples, you can check out examples.