This project has moved and is read-only. For the latest updates, please go here.

Callbacks

Dec 5, 2010 at 11:03 AM

Hi,

Nice engine! I'm trying to do a simple callback, is this possible? I have this basic example:

var engine = new Jurassic.ScriptEngine();
var script = @"
function abc()
{
    puts('hello');
}
test(abc);
";

engine.SetGlobalFunction("puts", new Action<string>((msg) => { Console.WriteLine(msg); }));
engine.SetGlobalFunction("test", new Func<FunctionDelegate, object>((fn) =>
{
    return null;
}));
engine.Execute(script);

I get the error Unhandled Exception: System.NotImplementedException: Unsupported parameter type 'Jurassic.Library.FunctionDelegate'.

Can suggest what I may be doing wrong?

Thanks

Dec 5, 2010 at 12:19 PM

As the error message suggests, FunctionDelegate is not supported as a method parameter type.  Use FunctionInstance instead.

The supported types are documented here: http://jurassic.codeplex.com/wikipage?title=Supported%20types&referringTitle=Documentation (FunctionInstance is not explicitly mentioned, but is a derived from ObjectInstance).

Dec 5, 2010 at 12:27 PM

By the way, congrats for being the first poster :-)

You don't win a prize, sorry :-(