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:

> 
> Sorry been busy getting sun burnt in Spain but am back now ;)
> 
> I shall have a look through this stuff now.  I also need to think about how
> JavaScripts prototype object inheritance works some more and how it is best
> exposed - to see how well it would currently fit into the existing
> beginnings of the framework.  Peter have you had any ideas about this?
> 
> Warrick.

I just came back from holiday myself, but have had some time to think on this 
project. I have not thought about inheritance yet. 
I had some ideas on a generic calling convention:

I think we need a generic argument list to hide the Script-specific details of 
the argument list. This may have been discussed already, but still:

If we could have common argument list interface, we could have a common langbind 
 calling mechanism:

Example for functions with 1 argument:
template<>
struct caller<2> {
    template<typename function_type,typename ArgumentListT>
    void_type_return call(function_type function, ArgumentListT& arguments,
free_function_void*)
    {
       function(arguments.a0,arguments.a1)());
       return void_type_return();
    }
    template<typename function_type,typename ArgumentListT>
    ArgumentListT::return_type call(function_type function, ArgumentListT& 
arguments,free_function*)
    {
       return function(arguments.a0,arguments.a1)());
    }
}

where ArgumentListT could be a tuplet of some sort:
template<typename SignatureT>
struct javascript_argument_list
{
  javascript_argument_list(JSContext *cx, JSObject *obj, unsigned int argc, 
jsval *argv, jsval *rval);

}

Then the only function callback we would need to write in order to interface 
with spidermonkey would be:
template<typename SignatureT,unsigned index>
struct function_callback {
    typedef SignatureT::value_type function_type;
    static function_type function;
    
    //Specializations for different call protocols
    static JSBool callback(JSContext *cx, JSObject *obj, unsigned int argc, 
jsval *argv, jsval *rval)
    {
        *rval=wrap(detail::caller<SignatureT::arity>::call(function,
javascript_argument_list<SignatureT>(cx,obj,argc,argv,rval),(SignatureT::
type_tag*)NULL);
        return JS_TRUE;
    }
};

I hope this makes some sense :)

> 
> -----Original Message-----
> From: Daniel Wallin [mailto:dalwan01 <at> student.umu.se]
> Sent: 28 March 2004 02:36
> To: boost-langbinding <at> lists.sourceforge.net
> Subject: Re: [Boost-langbinding] Re: Netscape 'Spidermonkey' JavaScript
> bindings
> 
> 
> Daniel Wallin wrote:
> > David Abrahams wrote:
> > 
> >> <snip>
> >>






-------------------------------------------------------
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.