Javascript Interpreter for C# (no dependencies)
#scripting #script-engine
|
11 жил өмнө | |
---|---|---|
.nuget | 11 жил өмнө | |
Jint | 11 жил өмнө | |
Jint.Benchmark | 11 жил өмнө | |
Jint.Repl | 11 жил өмнө | |
Jint.Tests | 11 жил өмнө | |
Jint.Tests.CommonScripts | 11 жил өмнө | |
Jint.Tests.Ecma | 11 жил өмнө | |
Jint.Tests.Scaffolding | 12 жил өмнө | |
.gitignore | 12 жил өмнө | |
CREDITS.txt | 11 жил өмнө | |
Jint.sln | 11 жил өмнө | |
Jint.sln.DotSettings | 11 жил өмнө | |
LICENSE.txt | 11 жил өмнө | |
README.md | 11 жил өмнө |
Jint is a Javascript interpreter for .NET. Jint doesn't compile Javascript to .NET bytecode and in this sense might be best suited for projects requiring to run relatively small scripts faster, or which need to run on different platforms.
This example defines a new value named log
pointing to Console.WriteLine
, then executes
a script calling log('Hello World!')
.
var engine = new Engine()
.SetValue("log", new Action<object>(Console.WriteLine))
;
engine.Execute(@"
function hello() {
log("Hello World");
};
hello();
");
Here, the variable x
is set to 3
and x * x
is executed in JavaScript. The result is returned to .NET directly, in this case as a double
value 9
.
var square = new Engine()
.SetValue("x", 3)
.Execute("x * x")
.ToObject()
;
You can also directly pass POCOs or anonymous objects and use them from JavaScript. In this example for instance a new Person
instance is manipulated from JavaScript.
var p = new Person {
Name = "Mickey Mouse"
};
var engine = new Engine()
.SetValue("p", p)
.Execute("p.Name === 'Mickey Mouse')
;
Status:
TODO: