Note: This feature is experimental and may be unstable
To call code in non-.NET (unmanaged) DLLs, consider using externs
.NET DLLs can be referenced in a limited manor. References only work if the imported metadata can be represented in native Belte. For example, referencing a C# property from a DLL will not work as Belte does not currently have properties. (Though for properties in particular, workarounds exist.)
Because of this limitation, the safest way to interact with imported references is through static methods defined in the DLL.
To specify a reference, the
--ref=<file> command-line argument can be used. Also note
that a few libraries can be added automatically by using -l# options.
For example:
buckle MyProgram.blt -d --ref="C:/Program Files/dotnet/packs/Microsoft.NETCore.App.Ref/10.0.3/ref/net10.0/System.Runtime.Intrinsics.dll" -o MyProgram.exe
This would allow you to interact with the System.Runtime.Intrinsics and constituent namespaces directly. Here is an
example of adding two Vector128<float32> structs together using SIMD:
using System.Runtime.Intrinsics.X86;
using System.Runtime.Intrinsics;
var a = Vector128.Create((float32)1, 2, 3, 4);
var b = Vector128.Create((float32)1, 2, 3, 4);
var c = Sse.Add(a, b);
Console.PrintLine(c);
Output:
<2, 4, 6, 8>
Interacting with C# properties is very straightforward. Properties define a getter and setter method that can be called directly:
using System.Collections.Generic;
var a = new List<int>();
a.Add(3);
var b = a.get_Item(0);
a.set_Item(0, 5);
Where a.get_Item(0) is equivalent to a[0] and a.set_Item(0, 5) is equivalent to a[0] = 5 in C#.
.NET/C#’s T[] is equivalent to Belte’s Buffer<T>, but Belte’s T[]/Array<T> does define implicit conversions to
and from Buffer<T>, so either type can be used when interacting with .NET libraries.
.NET’s nullability guarantees are weaker than Belte’s, so any reference type R will be treated as R? in Belte.
However, R! can be passed to R? implicitly so it is recommended to still constrain nullability wherever possible.
When it comes to value types V and V?, they are equivalent in Belte.