Lokad.Starlark is a .NET implementation of the Starlark language with a hermetic core runtime and a host extension model. The interpreter targets net8.0 and net10.0, uses Lokad.Parsing for the parser, and ships with a portable conformance suite derived from the Bazel Starlark tests.
Planned NuGet package name: Lokad.Starlark (unpublished for now).
using Lokad.Starlark;
using Lokad.Starlark.Runtime;
var interpreter = new StarlarkInterpreter();
var environment = new StarlarkEnvironment();
environment.AddFunction(
"add",
(args, kwargs) =>
{
var left = (StarlarkInt)args[0];
var right = (StarlarkInt)args[1];
return new StarlarkInt(left.Value + right.Value);
},
isBuiltin: true);
interpreter.ExecuteModule(
"result = add(2, 3)",
environment);Conformance scripts live under tests/Lokad.Starlark.Tests/TestData/Conformance, split into go, java, and rust subsets. Each file contains multiple cases separated by ---, and error expectations are annotated with ### (regex) on the failing statement.
Run the full suite with:
dotnet test --tl:off --nologo -v minimalThe CLI is a local demo utility (not packaged in the NuGet) with two modes: a hermetic REPL and a script runner. It injects a print helper to demonstrate host extensibility.
The exec command runs inline source for quick experiments and fuzzing.
Start the REPL:
dotnet run --project tools/Lokad.Starlark.Cli -- replRun a script file:
dotnet run --project tools/Lokad.Starlark.Cli -- run path\to\script.starRun inline source:
dotnet run --project tools/Lokad.Starlark.Cli -- exec "print(1 + 2)"