Embed · Host · Script

ThinBasic.NET

.NET Wrapper for the ThinBasic Scripting Engine

thinCore.dll .NET 8 / 9 / 10 Windows x86 NuGet Host Keywords MIT License

Embed ThinBasic scripts in .NET apps, inject host constants and keywords, parse callback arguments, work with arrays, isolation, hash tables, and module classes — all through a clean C# API.

What You Can Do

Embed Scripts

Init the engine, run .tbasic buffers or files, and release cleanly from any .NET host.

Host Keywords

Register managed delegates as ThinBasic symbols — numbers, strings, and full parser callbacks.

Equates & Variables

Inject constants and variables from the host; read and change script-side state at runtime.

Arrays & Direct Access

Inspect arrays, redim, and use direct variable pointers for high-performance host integration.

Isolation Mode

InitIsolated extracts modules into a dedicated directory — ideal for sandboxed hosts.

Classes & Hash Tables

Register module classes with methods/properties, plus thinCore string hash table APIs.

API Surface

High-level coverage of thinCore.dll

Lifecycle

Init InitIsolated InitCheckScript Run Release AddIncludePath

Host Data & Keywords

AddEquate AddVariable LoadSymbol / Ex AllocReturnString ClearSymbolCallbacks

Parser

CheckOpen/CloseParens CheckComma ParseNumber / String PutBack GetToken

Arrays · Isolation · Hash · Classes

ArrayGet* / Redim IsIsolated HashNew / Set / Get ClassAdd / Method / Property ParseClass

Quick Start

Init · inject host symbols · run script · release

Program.cs C# · x86
using ThinBasic.NET.Core;

int h = Thinbasic.Init(0, 0, "thinbasic");
if (h != 0)
{
    Console.WriteLine("Init failed: " + Thinbasic.GetLastError());
    return;
}

Thinbasic.AddEquate("%HOST_EQ", string.Empty, 7, (int)Enums.EquateType.Number);

int hostCalls = 0;
Thinbasic.LoadSymbol("HostFlag", () => hostCalls++, Enums.ForceOverWrite);
Thinbasic.LoadSymbol("HostNum", () => 123.5, Enums.ForceOverWrite);
Thinbasic.LoadSymbol("HostStr$", () => Thinbasic.AllocReturnString("hello"), Enums.ForceOverWrite);

string script = File.ReadAllText(@"Sample\test.tbasic", Encoding.UTF8);
int result = Thinbasic.Run(
    h, script, (int)Enums.BufferType.IsScript,
    0, 0, 0, 0,
    (int)Enums.CallingProgram.Console, 0);

int lastError = Thinbasic.GetLastError();
Thinbasic.Release(h);
Thinbasic.ClearSymbolCallbacks();
Parser callback
Thinbasic.LoadSymbol("HostAdd", () =>
{
    if (Thinbasic.CheckOpenParensMandatory() == 0) return 0;
    Thinbasic.ParseNumber(out double a);
    if (Thinbasic.CheckCommaMandatory() == 0) return 0;
    Thinbasic.ParseNumber(out double b);
    if (Thinbasic.CheckCloseParensMandatory() == 0) return 0;
    return a + b;
}, Enums.ForceOverWrite);

Important Notes

Windows x86 Only

Bundled thinCore.dll is 32-bit. Target PlatformTarget=x86 (or Prefer 32-bit). x64/Arm64 cannot load the native DLLs.

ANSI BSTR Strings

thinCore uses ANSI BSTRs. Prefer ASCII / system-ANSI-safe text. Return strings with AllocReturnString — do not free them yourself.

Callback Lifetime

Delegates passed to LoadSymbol stay rooted until ClearSymbolCallbacks(). Call it only when no script can still invoke those keywords.

Runtime Errors

Script errors may show a thinBasic dialog and leave engine state sticky. Prefer validating scripts; avoid relying on failed Run in long-lived hosts.

Get Started

NuGet install · build · examples

NuGet

Install-Package ThinBasic.NET

# or
dotnet add package ThinBasic.NET

Build & Test

dotnet build ThinBasic.NET\ThinBasic.NET.csproj -c Release -p:Platform=x86
dotnet test ThinBasic.NETTests\ThinBasic.NETTests.csproj -c Release -p:Platform=x86

Examples

dotnet run --project ThinBasic.Example -c Release -p:Platform=x86 -- embed
# host | parser | array | isolated | hash | class

Requirements

Windows 10+ · x86 only · .NET 8 / 9 / 10 (windows) · ships thinCore.dll + thinBasic_UI.dll (ThinBasic 1.14 era)

Script from .NET

Install the package, target Windows x86, and embed ThinBasic in your host application in minutes.