Zero-Based Indexing
Field indices, operator indices, and integrator references inside the engine are zero-based.
Oakfield exposes a composable operator calculus through Lua. A script creates a SimContext, adds fields and operators, assigns an integrator, then advances time. All APIs documented here are verified against the current source.
Zero-Based Indexing
One-Based Lua Tables
field:shape(), field:values()) are 1-based (Lua default).Complex Number Representation
{re, im} table.Enum Helpers
Data Layout
Coordinate Systems
Boundary Conditions
Userdata objects (contexts, fields, operators, integrators, loggers, profilers) are managed by Lua’s garbage collector (GC). Each userdata type has specific metamethods and GC behaviors:
| Type | Metamethods | GC Behavior |
|---|---|---|
Context (SimContext) | __gc, __tostring | Destroys context, releases managed integrators, frees native memory. |
| Field | __gc, __tostring, methods: rank, shape, values, components | GC detaches handle only (sets pointers NULL); underlying field owned by context until context GC. |
| Operator | __gc, __tostring, methods: name, symbolic_form | GC detaches handle only; operator lifetime owned by context. |
| Integrator | __gc, __tostring | GC destroys integrator and frees workspace. |
| Logger | __gc, __tostring, methods: log, pop, clear | GC destroys async logger and frees memory. |
| Profiler | __gc, __tostring, methods: begin_frame, end_frame, record_operator, record_operator_delta, snapshot | GC destroys profiler and frees memory. |
Detaching (field/operator) means subsequent method calls on that handle error (expected Field userdata).