Compile · Host · Execute

OxygenBasic.NET

.NET Wrapper for the OxygenBasic Compiler

oxygen.dll .NET 8 / 9 / 10 Windows x86 (prefer) NuGet JIT / Host API MIT License

Host OxygenBasic scripts from .NET — resolve include paths, share memory with the host, compile with O2Basic, and execute in one clean API surface.

What You Can Do

One-Shot Run()

High-level API: InitHost → Pathcall → O2Basic → Exec in a single call with OxygenHostOptions.

Include-Path Callback

Resolve %app_includepath% from the host so scripts can include your .inc files safely.

Shared .NET Memory

Pin host variables and let Oxygen scripts read/write them — ideal for counters, buffers, and interop.

Low-Level Control

Call InitHost, Pathcall, Varcall, O2Basic, Exec, Errno yourself when you need finer control.

Error Handling

Throws OxygenException on compile/runtime errors, or set ThrowOnError = false and inspect OxygenRunResult.

NuGet Ready

Ships oxygen.dll (x86) / oxygen64.dll (x64) with runtime DllImport resolver. Install and go.

API Surface

High-level host flow and core engine calls

High-Level Host

Oxygenbasic.Run OxygenHostOptions IncludeRoot VarResolver ThrowOnError OxygenRunResult OxygenException

Engine Lifecycle

InitHost Pathcall Varcall O2Basic Exec Errno Buf / Lib / Link / Eval

Since 1.0.8: O2Basic, Exec, Buf, Lib, Link, Eval return IntPtr — compare with IntPtr.Zero, not > 0.

Quick Example

Hosted script with include path and optional variable resolver

High-level Run C#
OxygenRunResult result = Oxygenbasic.Run(script, new OxygenHostOptions
{
    IncludeRoot = @"Sample\inc",
    VarResolver = name => /* optional host variable lookup */
});
Step-by-step InitHost → Pathcall → O2Basic → Exec
Oxygenbasic.InitHost();
Oxygenbasic.Pathcall(path => /* resolve %app_includepath% to Sample\inc */);
Oxygenbasic.Varcall(name => /* optional host variable lookup */);

// Script uses: includepath "%app_includepath%" / include "math_helpers.inc"
Oxygenbasic.O2Basic(script);
if (Oxygenbasic.Errno() == 0)
{
    Oxygenbasic.Exec();
}

Samples: Sample\hosted_demo.txt, Sample\inc\math_helpers.inc, Sample\test_fib.txt

Important Notes

Prefer x86

A 64-bit / AnyCPU process throws PlatformNotSupportedException instead of loading oxygen64.dll (DllMain AV). Prefer x86. Override with OXYGENBASIC_TRY_X64=1 only if you have a fixed native DLL.

Process-Global State

oxygen.dll is global to the process (single-threaded use). Abst() cannot be undone. See docs/oxygen-process-state.md.

Breaking Change (1.0.8)

O2Basic, Exec, Buf, Lib, Link, Eval now return IntPtr. Compare with IntPtr.Zero. See CHANGELOG.md.

CI Matrix

x86: build + test (net8/9/10) + hosted example. x64: build only (native tests skipped). See docs/oxygen64-x64-runtime.md.

Get Started

NuGet install · environment · examples

NuGet

Install-Package OxygenBasic.NET

# or
dotnet add package OxygenBasic.NET

Examples

# See OxygenBasic.Example
# hosted_demo · include path · shared memory
# test_fib · simple Fibonacci script

Requirements

Windows 10+ · OxygenBasic 0.90 · .NET 8 / 9 / 10 (Windows) · prefer x86 · ships oxygen.dll (x86) / oxygen64.dll (x64)

Compile Oxygen from .NET

Install the package, host a script with include paths and shared memory, and run it in a few lines of C#.