Skip to content

compile and bundle

While zolo build produces native machine code, the compile and bundle commands operate on the VM/Lua pipeline — the same one zolo run uses internally.

zolo compile prints to stdout the Lua code generated for the source file. It is useful for inspecting how Zolo transpiles expressions, closures, or f-strings before the VM executes them.

zolo bundle goes further: it traverses the entry point and all its imported modules, flattens everything into a single self-contained Lua file, and writes the result to the path specified by -o. The resulting file can be sent to any Lua 5.1 runtime without depending on the Zolo toolchain.

zolo compile shows the Lua for greet; zolo bundle -o app.lua writes the full program to a portable file.

05-compile-and-bundle.zolo
// Feature: source-level outputs — `zolo compile` and `zolo bundle`
// Syntax: `zolo compile file.zolo`  |  `zolo bundle file.zolo -o out.lua`
// When to use: `compile` shows the generated Lua source for the VM
//   target; `bundle` flattens an entry file + its modules into one Lua
//   file you can ship to any Lua 5.1 runtime.

// Run:
//   zolo compile 30-compilation/05-compile-and-bundle.zolo
//     # prints generated Lua to stdout
//   zolo bundle  30-compilation/05-compile-and-bundle.zolo -o app.lua
//     # writes a single self-contained Lua file
//
// These targets are about the VM/Lua pipeline (what `zolo run` uses),
// as opposed to `zolo build` which produces native machine code.

fn greet(name: str) -> str {
  return "Hello, {name}!"
}

print(greet("world"))

// expected (when run): Hello, world!

Requires the Zolo CLI/host — open in the playground or run locally.

Use zolo compile / zolo bundle when you need to inspect the intermediate VM output or generate a Lua artefact for environments that do not support the Zolo native runtime. For a standalone binary, prefer zolo build (chapter 30) or zolo build --emit zex (chapter 31).

See also

enespt-br