Getting started

Please follow the instructions to install ljc.

To ensure that everything went right, open a console and enter the command :

ljc -h

You should see the ljc help message with all the command line syntax and the available options.

Hello World !

As your first steps with ljc, we will compile a timeless classic "Hello World" program. To do so, please create a source file named "hello.lua" with the following content:

-- hello.lua

local msg = "Hello World !"

Hint : Before using ljc, please ensure that your Lua program is running without errors or bugs with the Lua (or LuaJIT) interpreter.

Using standard dynamic linking

To compile this main source file, enter the following command

ljc hello.lua

If everything went right, you should see the following output :

ljc hello.lua

At this time, you may notice :

  1. ljc outputs the file being compiled.
  2. ljc outputs the final executable dependencies, in this case lua53.dll, that are needed to run your program
  3. By default, ljc is linking the dynamic Lua 5.3 VM from the ljc runtime library
  4. ljc copy the binary dependencies (here lua53.dll) in the same directory as the compiled executable.

Run your program with the following command, to see this classical message :

Hello World !

Using static linking

The hello program does not require any binary module. To avoid the lua53.dll dependency, you can link to the static Lua 5.3 ljc runtime library using the -s option :

ljc -s hello.lua

Please note the different output from ljc :

ljc -s hello.lua
Dependencies: None

You can run the hello.exe executable. You may notice a larger executable.

Hello Windows !

Now we will compile a program targeting the Windows subsystem that will display in a window the message "Hello Windows!". We will use the ffi module from LuaJIT :

-- hellowin.lua

local ffi = require('ffi')
ffi.cdef [[ int MessageBoxA(void *w, const char *txt, const char *cap, int type); ]]

local msg = "Hello Windows !"
ffi.C.MessageBoxA(nil, msg, "Ljc Windows program", 0)

Save this file and compile it with the command :

ljc -s -w -j hellowin.lua
Dependencies: None

Note the use of the -j flag that tells ljc to use the LuaJIT version of the ljc runtime library. The -w option compiles the program targeting the Windows Gui subsystem. You can now run the hellowin.exe executable and see the message in a MessageBox.