structrt

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package structrt provides the runtime glue the bytecode generator emits when lowering a `struct` declaration. It installs ONE global helper, `__struct_define(name, fieldNames) -> constructor`, mirroring the way native/enumrt installs `__enum_freeze`.

A `struct Point { x: number, y: number }` lowers to

local Point = __struct_define("Point", {"x", "y"})

The returned constructor is a plain callable. It supports both call forms the language exposes:

Point(1, 2)          -- positional: fields assigned in declaration order
Point{ x = 1, y = 2 } -- named: Lua's `f{}` call sugar, one table arg

A single table argument is treated as NAMED construction unless it carries an array element at index 1 (in which case it is positional). Instances carry a metatable whose `__type` is the struct name — so `typeof(p)` reports "Point" — and a `__tostring` for readable printing. Instances are ordinary mutable tables otherwise (records, not frozen values).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterStructRT

func RegisterStructRT(v *vm.VM)

RegisterStructRT installs __struct_define on the VM globals. Idempotent, like the other runtime registrars, so the REPL can replay it on :reset.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL