library_builder library
Public extension surface for registering LuaLike libraries from Dart.
This library exposes the same registration types that LuaLike uses for its built-in libraries. Import it when you want to add reusable namespaced libraries, builder-style objects with metatables, or native functions that participate in runtime services such as cached primitive values and lazy library loading.
A minimal library implementation extends Library, defines functions inside
registerFunctions(), and registers an instance through LibraryRegistry:
import 'package:lualike/library_builder.dart';
import 'package:lualike/lualike.dart';
class GreetingLibrary extends Library {
@override
String get name => 'greeting';
@override
void registerFunctions(LibraryRegistrationContext context) {
final builder = BuiltinFunctionBuilder(context);
context.define('hello', builder.create((args) {
final who = args.isEmpty ? 'world' : Value.wrap(args.first).unwrap();
return Value('hello, $who');
}));
}
}
Classes
- BuiltinFunction
- Abstract base class representing a built-in function in the interpreter.
- BuiltinFunctionBuilder
- Builds BuiltinFunction instances bound to a registration context.
- BuiltinFunctionGcRefs
- Optional interface for builtins that need to keep GC-visible references.
- Environment
- Represents a scope for variable bindings in the interpreter.
- Library
- Abstract base class for organizing standard library functions.
- LibraryContext
- Registration context passed to Library.registerFunctions.
- LibraryRegistrationContext
- Registration context that collects the exported values for a Library.
- LibraryRegistry
- Registry for all standard and user-defined libraries in a runtime.
- LuaChunkLoadRequest
- Request for loading source or binary chunk input through the active engine.
- LuaChunkLoadResult
- Result of loading a chunk through the active runtime engine.
- LuaRuntime
- Shared runtime capabilities required by stdlib, lualike IR VM, and the AST interpreter.
- Value
- Represents a value in the LuaLike runtime system.
- ValueClass
- Example usage: