Can any one point out as where can I get some tutorials about IronJS and how to call a method written in IronJS from C# 4.0
Thanks
C#4.0, IronJS
Can any one point out as where can I get some tutorials about IronJS and how to call a method written in IronJS from C# 4.0
Thanks
C#4.0, IronJS
There is now some good information from the author on the GitHub project wiki:
https://github.com/fholm/IronJS/wiki
There is a 'first steps' blog post here:
http://blog.dotsmart.net/2011/04/20/first-steps-with-ironjs-0-2/
And I have written several blog posts on IronJS including one that stej has linked. The post stej linked is actually current, but it only covers some basic aspects of embedding. IronJS has undergone a radical rewrite since my first posts so I have put notices on those posts directing to newer updates.
This post specifically covers the original poster's question about how to call JS code from C#:
http://newcome.wordpress.com/2011/03/13/embedding-ironjs-part-ii/
Here is a quick summary:
IronJS.Hosting.Context ctx = IronJS.Hosting.Context.Create();
ctx.Execute("hello = function() { return 'hello from IronJS' }");
IronJS.Box obj = ctx.GetGlobal("hello");
Func<IronJS.Function,IronJS.Object,IronJS.Box> fun =
obj.Func.Compiler.compileAs<Func<IronJS.Function,IronJS.Object,IronJS.Box>>(obj.Func);
IronJS.Box res = fun.Invoke(obj.Func, obj.Func.Env.Globals);
Console.WriteLine( res.String );
Checkout https://github.com/fholm/IronJS/wiki for guides on using IronJS
If you have a Context
, you can call Context.CompileSource()
and pass its results to Context.InvokeCompiled()
, or just call Context.Execute()
and pass it the source code. Roughly, this:
IronJS.Hosting.Context ijsCtx;
ijsCtx = IronJS.Hosting.Context.Create();
ijsCtx.Execute("(function(){return 42;})()");
bin
directory after you build the project –
Zoometry You might have a look at Embedding IronJs. But it looks outdated as well as the answer by @Gabe.
Currently it should be called like this:
var o = new IronJS.Hosting.Csharp.Context
o.Execute('var a = 10; a');
© 2022 - 2024 — McMap. All rights reserved.