Skip to content

Instantly share code, notes, and snippets.

@jochemstoel
Created January 7, 2018 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jochemstoel/ead8d90613c7d51aeaeddce5902e18ca to your computer and use it in GitHub Desktop.
Save jochemstoel/ead8d90613c7d51aeaeddce5902e18ca to your computer and use it in GitHub Desktop.
Example 2
using System;
using Microsoft.ClearScript.V8;
using Microsoft.ClearScript;
namespace v8repl
{
class Program
{
static void Main(string[] args)
{
var repl = new REPL();
var v8 = repl.GetInstance(); // shortcut
/* assign the whole .NET core library to mscorlib */
v8.AddHostObject("mscorlib", new HostTypeCollection("mscorlib"));
/* reference full namespace, for example:
* mscorlib.System.Console.WriteLine()
* mscorlib.System.IO.File.WriteAllText()
*/
/* expose the V8ScriptEngine type to the V8 context */
v8.AddHostType("V8ScriptEngine", typeof(V8ScriptEngine));
/* we can now do:
* var context1 = new V8ScriptEngine()
*/
repl.LoadFile("init.js"); /* evaluate our file init.js */
repl.Start();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment