Note: This README was generated by an AI (Claude) based on analysis of the source code. It may contain inaccuracies.
A JScript/C# scripting runtime for .NET on Windows. Compiles and executes JScript or C# source files as .NET assemblies on the fly, with support for modular imports, compilation caching, and reflection-based interop.
- Dynamic compilation & execution: Compiles JScript or C# source files into .NET assemblies at runtime and executes them immediately.
- Modular scripts: Use
@include/importdirectives to pull in other script files. Imported files are automatically compiled as libraries. - Compilation cache: Caches compiled assemblies keyed by source hash, runtime version, and architecture. Subsequent runs skip recompilation if nothing has changed.
- Reflection-based interop:
GNN.Scripting.Reflection.csprovides a C# bridge that lets JScript code dynamically invoke .NET methods, access properties, and instantiate classes. - Dual language support: JScript and C# can be used together within the same project.
| Path | Description |
|---|---|
lib/ |
Core runtime — compiler wrapper, preprocessor, cache, utilities, and reflection bridge |
build/compile.js |
Bootstrap script that locates the .NET runtime and invokes the compiler |
build/script.net.js |
Main entry point — parses options, compiles, and optionally runs the target |
run.js |
Windows Script Host (WScript) runner for end-user script execution |
test/ |
NUnit-based unit tests |
JScript / C# source file
→ Preprocessor (@include / @import expansion, dependency compilation)
→ Cache check (reuse compiled assembly if source is unchanged)
→ C# compiler (csc.exe / jsc.exe)
→ Execution (reflection-based invocation inside an AppDomain)
Run a script via Windows Script Host:
cscript run.js <script.js> [args...]
Or use the main entry point directly for more control:
cscript build/script.net.js [options] <source>
| Option | Description |
|---|---|
/debug |
Include debug information in the compiled assembly |
/out:<file> |
Write output assembly to the specified file |
/target:exe|winexe|library |
Compilation target type |
/lang:js|cs |
Source language (auto-detected if omitted) |
/import:none|standard|configured |
Assembly import strategy |
/cache[+|-] |
Enable or disable compilation caching |
/optimize |
Enable compiler optimizations |
The reflection bridge (lib/GNN.Scripting.Reflection.cs) lets JScript scripts interact
with .NET classes dynamically. After importing a C# file, you get a Class object that
can instantiate types and invoke methods via System.Reflection.
Given a C# library:
// MyLib.cs
namespace MyLib {
public class Greeter {
public string Name { get; set; }
public Greeter(string name) { Name = name; }
public string Greet() { return "Hello, " + Name + "!"; }
public static string Version() { return "1.0"; }
}
}// hello.js
import MyLib in 'MyLib.cs';
import GNN.Scripting.Reflection;
var Greeter = new Class('MyLib.Greeter', runner);
var g = Greeter.create('World');
WScript.Echo(g.invoke('Greet')); // -> "Hello, World!"
WScript.Echo(Greeter.invoke('Version')); // -> "1.0"
WScript.Echo(g.getProp('Name')); // -> "World"
g.setProp('Name', 'script.net');
WScript.Echo(g.invoke('Greet')); // -> "Hello, script.net!"On .NET 4.0+, Class and Instance extend DynamicObject, so JScript's dynamic typing
lets you call methods and read/write properties directly:
// hello.js
import MyLib in 'MyLib.cs';
import GNN.Scripting.Reflection;
var Greeter = new Class('MyLib.Greeter', runner);
var g = Greeter.create('World');
WScript.Echo(g.Greet()); // -> "Hello, World!" (= g.invoke('Greet'))
WScript.Echo(Greeter.Version()); // -> "1.0" (= Greeter.invoke('Version'))
WScript.Echo(g.Name); // -> "World" (= g.getProp('Name'))
g.Name = 'script.net'; // (= g.setProp('Name', ...))
WScript.Echo(g.Greet()); // -> "Hello, script.net!"| Method | Description |
|---|---|
Class.create(...args) |
Instantiate the .NET class; returns an Instance |
Class.invoke(method, ...args) |
Call a static method |
instance.invoke(method, ...args) |
Call an instance method |
instance.getProp(prop[, ...index]) |
Get a property or field value |
instance.setProp(prop, value[, ...index]) |
Set a property or field value |
instance.getItem(...index) |
Get an indexed item (shorthand for getProp('Item', ...)) |
instance.setItem(value, ...index) |
Set an indexed item (shorthand for setProp('Item', ...)) |
- Windows with .NET Framework (v1.0–v4.x)
- Windows Script Host (
cscript.exeorwscript.exe)