LinuxCommandLibrary

luac

Compile Lua source code into bytecode

TLDR

Compile a Lua source file to Lua bytecode

$ luac -o [byte_code.luac] [source.lua]
copy

Do not include debug symbols in the output
$ luac -s -o [byte_code.luac] [source.lua]
copy

SYNOPSIS

luac [options] [filenames]

PARAMETERS

-l
    Lists the bytecode of the compiled Lua source file(s) to standard output, without generating an output file. This is useful for inspecting the compiled code.

-o <output>
    Specifies the output file for the compiled bytecode. If this option is not provided, the default output file name is 'luac.out'.

-p
    Parses the input file(s) only for syntax errors. No bytecode is generated, and no output file is created. This option is useful for quick syntax checking.

-s
    Strips debug information (e.g., line numbers, local variable names) from the compiled bytecode. This can slightly reduce the file size and provide minor obfuscation, making decompilation harder.

-v
    Prints the version information of the Lua compiler (luac) to standard output.

-V
    Prints verbose version information, including details about the Lua core and its build configuration.

-
    Reads input from standard input (stdin) instead of a specified file. This allows piping content directly to luac.

--
    Signals the end of command-line options. Any arguments following '--' are treated as filenames, even if they begin with a hyphen.

DESCRIPTION

luac is the official Lua compiler, a utility program included with the Lua distribution. Its primary function is to compile Lua source code files into a binary representation known as Lua bytecode. This bytecode can then be executed by the lua interpreter.

Compiling scripts into bytecode offers several advantages: it can improve startup performance by skipping the parsing phase, subtly obfuscate source code from casual viewing (though it's not strong encryption), and allow for pre-distribution of compiled code. While Lua is primarily an interpreted language, luac facilitates a compile-then-run workflow, especially useful for larger applications or embedded systems where resource optimization is crucial.

CAVEATS

While luac compiles source code to bytecode, this bytecode is not truly secure and can often be decompiled using various tools. Additionally, Lua bytecode is generally not portable across different architectures or even different builds of Lua with varying integer or float sizes. This means bytecode compiled on one system might not run on another if their Lua Virtual Machine (VM) configurations differ significantly.

CROSS-PLATFORM CONSIDERATIONS

Lua bytecode is specific to the Lua VM version and the architecture on which it was compiled (e.g., endianness, size of int and float types). For maximum portability, it is generally recommended to distribute Lua source code and compile it on the target system, or to ensure that the target system's Lua environment closely matches the compilation environment.

HISTORY

Lua was first created in 1993 by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, and Waldemar Celes at PUC-Rio, Brazil. From its early versions, luac has been an integral part of the Lua distribution, providing a compile-time tool for preparing Lua scripts. Its inclusion reflects Lua's design philosophy of being a lightweight, embeddable language where pre-compilation can be beneficial for performance and resource-constrained environments. Over the years, luac has evolved alongside the Lua language, adapting to new bytecode formats and language features while maintaining its core functionality.

SEE ALSO

lua(1)

Copied to clipboard