Skip to content

Instantly share code, notes, and snippets.

@khebbie
Created October 1, 2011 19:08
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 khebbie/1256505 to your computer and use it in GitHub Desktop.
Save khebbie/1256505 to your computer and use it in GitHub Desktop.
Please add a reference to the IronJS.dll (the x86 version) to make it work
void Main()
{
var script = @"
var NumeralConverter = {
get_arabic_numeral : function ( romanNumeral ){
return 1;
}
}
var x = function(input) {
print('From within javascript function');
return input + 1;}
x(10);
print('testing');
retSome();
";
var ctx = new IronJS.Hosting.CSharp.Context();
ctx.SetGlobal("print", IronJS.Native.Utils.CreateFunction<Action<string>>(ctx.Environment, 1, Print));
ctx.SetGlobal("retSome", IronJS.Native.Utils.CreateFunction<Func<string>>(ctx.Environment, 1, retSome));
ctx.Execute(script).Dump();
//ctx.Globals.Members.Where(x => x.Key == "x").Dump();
var funcFromJavascript = ctx.GetGlobalAs<FunctionObject>("x");
funcFromJavascript.Call(ctx.Globals,"10").String.Dump();
}
void Print(string value)
{
Console.WriteLine(value.ToString());
}
string retSome()
{
return "Hej fra c#";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment