ThinBasic.NET 1.0.9

There is a newer version of this package available.
See the version list below for details.
dotnet add package ThinBasic.NET --version 1.0.9
                    
NuGet\Install-Package ThinBasic.NET -Version 1.0.9
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ThinBasic.NET" Version="1.0.9" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ThinBasic.NET" Version="1.0.9" />
                    
Directory.Packages.props
<PackageReference Include="ThinBasic.NET" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ThinBasic.NET --version 1.0.9
                    
#r "nuget: ThinBasic.NET, 1.0.9"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ThinBasic.NET@1.0.9
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ThinBasic.NET&version=1.0.9
                    
Install as a Cake Addin
#tool nuget:?package=ThinBasic.NET&version=1.0.9
                    
Install as a Cake Tool

ThinBasic.NET

.NET wrapper for the ThinBasic scripting engine (thinCore.dll).
Embed ThinBasic scripts in .NET apps, inject host constants/keywords, and parse callback arguments.

GitHub Nuget CI

Requirements

Item Detail
OS Windows 10+
Architecture x86 only (PlatformTarget=x86)
.NET net8.0-windows / net9.0-windows / net10.0-windows
Native Ships thinCore.dll + thinBasic_UI.dll (ThinBasic 1.14 era)

x64 / Arm64 processes cannot load the bundled 32-bit native DLLs.

NuGet

PM> Install-Package ThinBasic.NET

Consumer projects must target Windows x86 (or Prefer 32-bit) so thinCore.dll can load.

Important notes

Strings (ANSI BSTR)

thinCore string parameters/returns use ANSI BSTRs (SysAllocStringByteLen), not Unicode BStr / LPStr.
This package marshals them manually. Prefer ASCII / system-ANSI-safe text for symbol names and paths.

For ThinBasicStringCallback return values, allocate with:

return Thinbasic.AllocReturnString("hello");

Ownership of that BSTR is transferred to thinCore — do not free it yourself.

Callbacks and GC

LoadSymbol / LoadSymbolEx accept managed delegates and keep them rooted until:

Thinbasic.ClearSymbolCallbacks();

Call ClearSymbolCallbacks only when no script may still invoke those keywords.

Direct variable / array pointers

GetVariableNumberDirect / ChangeVariable*Direct need the return value of VariableGetInfoEx (variable structure pointer), not the DataPtr out-parameter.

Runtime errors

Script runtime errors may show a thinBasic error dialog and leave process-wide engine state dirty.
Prefer validating scripts; avoid relying on failed Run calls inside long-lived hosts.
GetLastError can remain sticky across Release / next Init in some failure paths.

Isolation

InitIsolated / InitCheckScript take an isolation directory for extracted modules/DLLs.
After InitIsolated, IsIsolated() is non-zero and IsolationPath() returns that path.
Isolation flags may remain set for the process after Release (thinCore global state).

Hash tables

HashNew / HashSet / HashGet / HashFree use thinCore’s internal string hash storage.
Init is not required. Keys are case-sensitive; always HashFree handles you create (including clones).

Quick start

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();

if (lastError != 0)
{
    Console.WriteLine("Script error: " + lastError);
}

Parser callbacks

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);

Isolation

string iso = Path.Combine(Path.GetTempPath(), "my-iso");
Directory.CreateDirectory(iso);

int h = Thinbasic.InitIsolated(0, 0, "thinbasic", iso);
// Thinbasic.IsIsolated() != 0
// Thinbasic.IsolationPath() ~= iso

Thinbasic.Run(h, "DIM n AS LONG\r\nn = 1\r\n",
    (int)Enums.BufferType.IsScript, 0, 0, 0, 0,
    (int)Enums.CallingProgram.Console, 0);

Thinbasic.Release(h);

Examples project

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

Build & test

Requires Visual Studio 2022/2026 (or .NET SDK 8+) on Windows.

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

API surface (summary)

Area Highlights
Lifecycle Init, InitIsolated, InitCheckScript, Run, Release, AddIncludePath
Host data AddEquate, AddVariable, ChangeVariable*, VariableGet*, FunctionSimpleCall
Keywords LoadSymbol / LoadSymbolEx (+ delegate overloads), AllocReturnString, ClearSymbolCallbacks
Parser CheckOpen/CloseParens*, CheckComma*, ParseNumber / ParseString, PutBack, GetToken*
Arrays VariableIsArray, ArrayGetElements / Ptr / Info, VariableRedim, *Direct
Isolation IsIsolated, IsolationPath, IsBundled, ResourcesCount / GetFile / GetBuffer
Hash HashNew / Free / Set / Add / Get / GetDefault / Exists / Del / Count / Clone / Clear / GetKeys / ToString / Cap* / Validate

License

Copyright (c) 2017-2026 Ji-Feng Tsai.
ThinBasic Copyright (c) Eros Olmi ThinBASIC Interpreter.
Code released under the MIT license.

TODO

  • More thinCore.dll APIs (class)

Donation

If this application help you reduce time to coding, you can give me a cup of coffee 😃

paypal

Paypal Me

Product Compatible and additional computed target framework versions.
.NET net8.0-windows7.0 is compatible.  net9.0-windows was computed.  net9.0-windows7.0 is compatible.  net10.0-windows was computed.  net10.0-windows7.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0-windows7.0

    • No dependencies.
  • net8.0-windows7.0

    • No dependencies.
  • net9.0-windows7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.10 152 8/14/2026
1.0.9 123 8/7/2026
1.0.8 133 7/31/2026
1.0.7 212 12/4/2024
1.0.6 226 1/31/2024
1.0.5 524 11/9/2022
1.0.4 533 11/11/2021
1.0.3 511 5/27/2021
1.0.2 641 6/29/2020
1.0.1 621 6/29/2020
1.0.0 765 8/27/2019

Hash table APIs (HashNew/Set/Get/Free, …); Isolation APIs; README docs for x86, ANSI BSTR, callbacks, and Direct pointers.