Information about IronJS
Asked Answered
D

4

11

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

Dispenser answered 25/10, 2010 at 5:47 Comment(1)
I'd be willing to bet that IronJS is too new to have tutorials.Zoometry
B
10

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 );
Burp answered 4/5, 2011 at 0:3 Comment(2)
I updated the tag wiki to include some of the links and content from the readme.Yell
With the latest IronJS this code snippet is depreciated as there isn't a 'IronJS.Box' there is an 'IronJS.BoxedValue' but it doesn't have a 'Func.Compile' method. The docs for IronJS are frustratingly lacking.Hootenanny
V
7

Checkout https://github.com/fholm/IronJS/wiki for guides on using IronJS

Ventriloquize answered 25/5, 2011 at 12:44 Comment(0)
Z
5

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;})()");
Zoometry answered 25/10, 2010 at 6:17 Comment(4)
Sir, 1 more question.. Last day i was trying to get the IronJS class from the available dlls. But not able to find out. Could you please let me nknow in which assembly it is ?Dispenser
IronJS is a namespace, not a class.Zoometry
Yes its a typo.. I mean in which dll i will get this IronJS.Hosting.Context ?Dispenser
It's in the IronJS.dll which will be in the bin directory after you build the projectZoometry
D
1

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');
Doyenne answered 20/4, 2011 at 7:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.