unity/nuget/README_JS.md
PuerTS is a scripting solution that brings JavaScript / TypeScript to your .NET applications. It provides high-performance script runtimes with seamless C# interop.
| Backend | Node API | Performance | Binary Size | Debugging |
|---|---|---|---|---|
| V8 | ❌ | ★★★★★ | ★★★ | ✔️ |
| QuickJS | ❌ | ★★ | ★ | ❌ |
| Node.js | ✔️ | ★★★★★ | ★★★★★ | ✔️ |
Install via NuGet. Choose one of the following Complete packages (includes core + native assets for all desktop platforms):
# V8 backend (recommended)
dotnet add package Puerts.V8.Complete
# Or Node.js backend (with Node API support)
dotnet add package Puerts.NodeJS.Complete
# Or QuickJS backend (minimal size)
dotnet add package Puerts.QuickJS.Complete
Or install components separately for finer control:
# Core library (required)
dotnet add package Puerts.Core
# Backend (choose one)
dotnet add package Puerts.V8
dotnet add package Puerts.NodeJS
dotnet add package Puerts.QuickJS
# Native assets per platform (choose what you need)
dotnet add package Puerts.V8.NativeAssets.Win32
dotnet add package Puerts.V8.NativeAssets.Linux
dotnet add package Puerts.V8.NativeAssets.macOS
.net8.0+, .netstandard2.1
| Windows (x64) | Linux (x64) | macOS (Universal) | |
|---|---|---|---|
| V8 | ✔️ | ✔️ | ✔️ |
| Node.js | ✔️ | ✔️ | ✔️ |
| QuickJS | ✔️ | ✔️ | ✔️ |
Note: AOT compilation is not currently supported.
Create a ScriptEnv with the backend matching your installed package:
| Installed Package | Backend Class |
|---|---|
Puerts.V8 / Puerts.V8.Complete | new BackendV8() |
Puerts.NodeJS / Puerts.NodeJS.Complete | new BackendNodeJS() |
Puerts.QuickJS / Puerts.QuickJS.Complete | new BackendQuickJS() |
using Puerts;
// Use the backend that matches your installed package:
// V8 → new BackendV8()
// Node.js → new BackendNodeJS()
// QuickJS → new BackendQuickJS()
var env = new ScriptEnv(new BackendV8());
// Execute JavaScript
env.Eval(@"
const Console = CS.System.Console;
Console.WriteLine('Hello from JavaScript!');
");
// Eval with return value
int result = env.Eval<int>("1 + 2");
Console.WriteLine($"JS result: {result}"); // output: 3
env.Dispose();
Access any .NET type via the CS namespace:
// Access C# types
const Console = CS.System.Console;
const DateTime = CS.System.DateTime;
const List = CS.System.Collections.Generic.List$1(CS.System.String);
// Create instances and call methods
let now = DateTime.Now;
Console.WriteLine('Current time: ' + now.ToString());
let list = new List();
list.Add('hello');
list.Add('world');
Console.WriteLine('Count: ' + list.Count);
using Puerts;
using System;
// Use the backend that matches your installed package
var env = new ScriptEnv(new BackendV8());
// Get a JS function as a C# delegate
var add = env.Eval<Func<int, int, int>>("(a, b) => a + b");
Console.WriteLine(add(10, 20)); // output: 30
// Get a JS action
var greet = env.Eval<Action<string>>(@"
(name) => {
const Console = CS.System.Console;
Console.WriteLine('Hello, ' + name + '!');
}
");
greet("PuerTS");
env.Dispose();
For full documentation, tutorials and API reference, visit: https://puerts.github.io/en