Created
October 1, 2011 19:08
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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