LuaBuilder class final

A builder that compiles Lua scripts at build time.

This builder implements the Builder interface from package:hooks and can be used in a hook/build.dart to compile Lua scripts at build time.

Compilation modes

Mode Output Runtime
CompileMode.bytecode build/lua/*.lua (binary) Load bytes, run bytecode VM
CompileMode.dartSource build/lua/*.lua.dart (Dart src) Import & call directly
CompileMode.dartEmbed build/lua/*.lua.dart (Dart src) Import bytes, run bytecode VM

Example -- bytecode mode (default)

import 'package:hooks/hooks.dart';
import 'package:lualike_hooks/lualike_hooks.dart';

void main(List<String> args) async {
  await build(args, (input, output) async {
    final builder = LuaBuilder(
      sources: ['assets/lua/'],
    );
    await builder.run(input: input, output: output, logger: null);
  });
}

Example -- Dart source mode

void main(List<String> args) async {
  await build(args, (input, output) async {
    final builder = LuaBuilder(
      sources: ['assets/lua/'],
      mode: CompileMode.dartSource,
    );
    await builder.run(input: input, output: output, logger: null);
  });
}

Constructors

LuaBuilder({required List<String> sources, CompileMode mode = CompileMode.bytecode, String outputDirName = 'lua', bool enableConstantFolding = true, bool enablePeephole = true, bool stripDebug = false})
Creates a LuaBuilder with the supplied configuration.
const

Properties

enableConstantFolding → bool
Whether to enable constant folding during compilation.
final
enablePeephole → bool
Whether to enable peephole optimization during compilation.
final
hashCode → int
The hash code for this object.
no setterinherited
mode → CompileMode
How the Lua source should be compiled and embedded.
final
outputDirName → String
The name of the output directory under build/.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
sources → List<String>
The directories containing Lua source files to compile.
final
stripDebug → bool
Whether to strip debug information from the compiled bytecode.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
run({required BuildInput input, required BuildOutputBuilder output, required Logger? logger}) → Future<void>
Runs the Lua compilation process.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited