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

AliasDescriptor
Concrete DocDescriptor for a type alias.
AliasDoc
Describes a type alias (---@alias).
AliasVariant
A single variant in a string literal union alias.
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.
ConstantDescriptor
Concrete DocDescriptor for a constant value.
DocDescriptor
A documentation descriptor that pairs with LibraryRegistrationContext.define to declare an exported value's type and metadata.
DocParam
Describes a single parameter accepted by a library function.
EnumDescriptor
Concrete DocDescriptor for an enum table.
EnumDoc
Describes an enum table (---@enum).
Environment
Represents a scope for variable bindings in the interpreter.
FieldDoc
Describes a single field in a Lua table schema.
FunctionDescriptor
Concrete DocDescriptor for a callable function.
FunctionDoc
Documentation for a Lua-standard-library function or constant.
GenericParam
Declares a generic type parameter on a function or class.
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.
OperatorDoc
Describes a Lua operator metamethod declaration (---@operator).
OverloadDoc
An alternative overloaded signature for a function.
TableDescriptor
Concrete DocDescriptor for a table schema.
TableDoc
Describes the expected shape of a Lua table value.
Value
Represents a value in the LuaLike runtime system.
ValueClass
Example usage:
ValueDoc
Documents a constant value or typed global variable.

Enums

AccessScope
Controls visibility of functions, fields, and class members in generated LuaLS annotations.