Re: Netscape 'Spidermonkey' JavaScript bi ndings

Peder Holt <[email protected]>
Newsgroups gmane.comp.lib.boost.langbinding
Message-ID <[email protected]>
Warrick Buchanan <Warrick <at> argonaut.com> writes:

> 
> Hi,
> 
> The method I've been investigating currently for binding was to generate a
> unique jsNative wrapper function that is made unique by the template
> parameters of the class type and function signature combined with a unique
> id (The <0> etc in my previous examples).  So for a function that takes one
> argument and returns something it's like (from memory as my code is at home
> at the moment):
> 
> template<class Class>
> struct Declare
> {
> 	static std::vector<JSFuncSpec> functionSpecs;
> 
> 	template<int id, class ReturnType, class Arg0Type>
> 	struct BindFunction
> 	{
> 		typedef ReturnType (Class::*Prototype)(Arg0Type);
> 
> 		static Prototype function;

I agree. It is better to use static member data to store the function pointer 
locally. I didn't think MSVC 6.5 supported member data in template classes, but 
it works as long as the classes are not nested, and the member data is 
explicitly "instantiated" outside of the class body. I had to do some rewriting 
to make MSVC 6.5 happy, but the essence is more or less the same as in your 
code.

> Declare<Vector3>::Property<float, &Vector3::x>();

This syntax does not go very well with non-conformant compilers. 
We have to live with the extra int argument to the template, but by adopting the 
boost::python syntax for defining functions, we can hide it from the user.

I have written a generic callback mechanism for functions with N arguments using 
the above techniques + boost::preprocessor. The main problem will be generic 
type conversion. This is probably the first thing that should be generalized 
between differen language binders. 

>> Would you be interested in combining efforts on this problem?

> Absolutely.

Great! I was thinking of creating a separate cvs branch under the clipp code 
branch. Does that sound like a plan?

I will be on vacation till after the easter holiday.

Peder Holt



-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.