More test codes

Jul 25, 2013 at 8:17 AM
Hi jamesnw,

Would be great if there are more test codes to demonstrate the capability of this library such as invoking callbacks (from .Net to JS or vice versa).

Not sure whether its possible to pass in things such as HttpClient or Stream object?

Thanks!
Coordinator
Jul 25, 2013 at 11:20 AM
Edited Jul 25, 2013 at 1:47 PM
There is an example of wrapping 'Console.WriteLine()' in the console app (program.cs). That said, I'll try to add this to the online documentation - perhaps a section on how to talk back and forth. Thanks for the suggestion! :)
Coordinator
Jul 25, 2013 at 1:47 PM
I assume you are referring to the console commands? I'll probably add an example first and use that for the online doc also.
Jul 31, 2013 at 11:59 AM
Hi jamesnw, thanks for the quick response.

What I meant was .net passing delegate to javascript as callbacks or from javascript to .net.

Out of topic, I've read about streams in nodejs (http://blog.strongloop.com/practical-examples-of-the-new-node-js-streams-api/) and just wondering whether we can achieve something similar for V8.net.
Coordinator
Jul 31, 2013 at 12:52 PM
Edited Jul 31, 2013 at 2:38 PM
Oh, for that You have to create a function callback using function templates, then assign the function object handle to a property. I guess you are looking for way to have it done automatically for delegates. The best course for me is to create a method that will help wrap a supported delegate (JSFunction I think) and then you can handle the parameters as you need to. You could easily pass it a lambda expression and then call your custom delegate.

BTW: I am working on binding logic to help expose .net object types and instances, to make things much easier. :)

Streaming will be available as part of the DreamSpace project (see related projects), which is my .Net answer to NodeJS. :)
Coordinator
Jul 31, 2013 at 4:33 PM
Edited Aug 1, 2013 at 4:29 AM
I decided to go ahead and create a V8Engine method to wrap a given delegate object. It will be available in the next release. :)

Note: The parameter types will be converted as best possible, which is always slower (because of the dynamic nature) - it will be faster to create your own:
Example: var func = {V8Engine}.CreateFunctionTemplate("OptionalClassName").GetFunction((...)=>{ /*call your method/delegate here*/ });
// ... then you can pass 'func' to a 'SetProperty()' method.
Aug 1, 2013 at 2:15 AM
Great! Apart from dynamic GetFunction(), you can add a GetFunction<T>() as well to improve the speed?
Coordinator
Aug 1, 2013 at 4:25 AM
Edited Aug 1, 2013 at 3:23 PM
GetFunction<T>() is just a way to return your own custom object that inherits from V8Function. :) The "T" simply defaults to "V8Function" when you call the non-generic version. There's really not much difference between the two, except the generic version is where the actual code resides to create and return the function object.