Hi, all!

After a long hacking session i would like to announce what is very possibly
the world's simplest method for binding C++ functions and methods to v8...

ToInCa ("InCa" is short for "InvocationCallback") is a class template which
can convert free functions and member functions to InvocationCallback
functions at compile-time. Those InCa instances can then be bound to
arbitrary JS objects (member binding requires that the JS object and a
native object of that type have been bound together, of course).

e.g. to bind the Unix sleep() function:

v8::InvocationCallback cb = ToInCa<void, unsigned int (unsigned int),
::sleep>::Call;

or a non-const method of a JS-bound class:

cb = ToInCa<MyType, returnType (argType1,... argTypeN), &MyType::foo>::Call;

or a const method:

cb = ToInCa<MyType, double (double, int) const, &MyType::bar>::Call;


ToInCa is part of the v8::convert library, a templates-heavy, header-only
spin-off of the v8::juice project which focuses primarily on converting
types between v8/JS and C++. ToInCa is basically the culmination of that
work so far, combining several relatively complex features into a small,
simple interface. It also provides infrastructure which templating wizards
can use to do weird things like choosing a different code path based on the
type of the type of 3rd argument in a given function call. With that in
place it will become feasible (but not trivial) to be able to bind overloads
of functions which dispatch based on the types of the arguments they get at
runtime (we can already overload them based on their arity). (That said, my
template-fu isn't _quite_ that good.)

Here's a link which jumps straight to some docs and demo code:

http://code.google.com/p/v8-juice/wiki/V8Convert#Converting_Functions_to_v8::InvocationCallback

Happy Hacking!


-- 
----- stephan beal
http://wanderinghorse.net/home/stephan/

-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users

Reply via email to