Hi, all!

Since the topic of using macros for binding C++ to JS came up recently, i
felt compelled to throw together a demonstration of a template-based
mechanism which is 100% type-safe, easy to use, probably more readable
THAN_A_BUNCH_OF_MACROS(). Templates are damned fine voodoo which can be used
to solve most C++/JS binding issues very well.

So... here's how to bind a C++ class to JS in about 2 minutes using
templates:

http://code.google.com/p/v8-juice/wiki/V8Convert_ClassCreator

One of the bigger advantages of templates is that they can, in contrast to
macros, take care of "the little details", like whether or not we can safely
use v8::Unlock to unlock v8 while we call bound functions (and such things
can often be added/changed without touching client code using the
macr^H^H^H^H templates). In the above code, we determine at compile-time
whether or not Unlock can/should be used by looking at all the arguments of
a function call - if any are v8 types, we disable unlocking, else we assume
it's okay to unlock (but locking can be explicitly disabled as a template
option).

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