-
Notifications
You must be signed in to change notification settings - Fork 83
Creating a hosting context
Creating a hosting context for IronJS is very simple, first you open the namespaces and modules you'll need:
open IronJS
module IronJS = IronJS.Hosting.FSharpThen call createContext on the IronJS.Hosting.FSharp (aliased as IronJS):
let ctx = IronJS.createContext()To execute JavaScript source code you have access to the following methods on the Hosting.FSharp module
execute : string -> IronJS.Hosting.FSharp.T -> objexecuteAs<'a> : string -> IronJS.Hosting.FSharp.T -> 'aexecuteFile : string -> IronJS.Hosting.FSharp.T -> objexecuteFileAs<'a> : string -> IronJS.Hosting.FSharp.T -> 'a
For working with global values you have access to the following fucntions:
setGlobal: string -> obj -> IronJS.Hosting.FSharp.T -> unitgetGlobal: string -> IronJS.Hosting.FSharp.T -> IronJS.BoxedValuegetGlobalAs<'a>: string -> IronJS.Hosting.FSharp.T -> 'a
You can also access the IronJS environment object and the globals object with the following functions
env: -> IronJS.Hosting.FSharp.T -> IronJS.Environmentglobals: -> IronJS.Hosting.FSharp.T -> IronJS.CommonObject
The process in C# works almost the same as in F#, but the API is more C#-like, you create an instance of the IronJS.Hosting.CSharp.Context object:
var ctx = new IronJS.Hosting.CSharp.Context();You then have access to the following methods and properties on the context object to run JavaScript code, work with globals and modify the environment:
Execute(string)ExecuteAs<T>(string)ExecuteFile(string)ExecuteFileAs<T>(string)SetGlobal(string, obj)GetGlobal(string)GetGlobalAs<T>(string)EnvironmentGlobals