Skip to content

Repository files navigation

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.NETthinBasicNugetCI

Requirements

ItemDetail
OSWindows 10+
Architecturex86 only (PlatformTarget=x86)
.NETnet8.0-windows / net9.0-windows / net10.0-windows
NativeShips 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:

returnThinbasic.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

usingThinBasic.NET.Core;inth=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);inthostCalls=0;Thinbasic.LoadSymbol("HostFlag",()=>hostCalls++,Enums.ForceOverWrite);Thinbasic.LoadSymbol("HostNum",()=>123.5,Enums.ForceOverWrite);Thinbasic.LoadSymbol("HostStr$",()=>Thinbasic.AllocReturnString("hello"),Enums.ForceOverWrite);stringscript=File.ReadAllText(@"Sample\test.tbasic",Encoding.UTF8);intresult=Thinbasic.Run(h,script,(int)Enums.BufferType.IsScript,0,0,0,0,(int)Enums.CallingProgram.Console,0);intlastError=Thinbasic.GetLastError();Thinbasic.Release(h);Thinbasic.ClearSymbolCallbacks();if(lastError!=0){Console.WriteLine("Script error: "+lastError);}

Parser callbacks

Thinbasic.LoadSymbol("HostAdd",()=>{if(Thinbasic.CheckOpenParensMandatory()==0)return0;Thinbasic.ParseNumber(outdoublea);if(Thinbasic.CheckCommaMandatory()==0)return0;Thinbasic.ParseNumber(outdoubleb);if(Thinbasic.CheckCloseParensMandatory()==0)return0;returna+b;},Enums.ForceOverWrite);

Isolation

stringiso=Path.Combine(Path.GetTempPath(),"my-iso");Directory.CreateDirectory(iso);inth=Thinbasic.InitIsolated(0,0,"thinbasic",iso);// Thinbasic.IsIsolated() != 0// Thinbasic.IsolationPath() ~= isoThinbasic.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)

AreaHighlights
LifecycleInit, InitIsolated, InitCheckScript, Run, Release, AddIncludePath
Host dataAddEquate, AddVariable, ChangeVariable*, VariableGet*, FunctionSimpleCall
KeywordsLoadSymbol / LoadSymbolEx (+ delegate overloads), AllocReturnString, ClearSymbolCallbacks
ParserCheckOpen/CloseParens*, CheckComma*, ParseNumber / ParseString, PutBack, GetToken*
ArraysVariableIsArray, ArrayGetElements / Ptr / Info, VariableRedim, *Direct
IsolationIsIsolated, IsolationPath, IsBundled, ResourcesCount / GetFile / GetBuffer
HashHashNew / 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

About

.Net Wrapper for ThinBasic Programming Language

Topics

Resources

Stars

2 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages