Quantcast

pass function to C API

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

pass function to C API

Mihai Dobrescu
Hello,

I have a C API to embed. There, it is some function needing a function as argument:


typedef SPAPI SPErr (*SPPluginEntryFunc)( const char *caller, const char *selector, void *message );

...

typedef struct SPPluginsSuite {
...
        SPAPI SPErr (*GetPluginHostEntry)( SPPluginRef plugin, SPPluginEntryFunc *host );
....
}

Could this be achieved in SpiderMonkey by passing some javascript implemented function to the C API?

Thank you.
_______________________________________________
dev-tech-js-engine mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-js-engine
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: pass function to C API

Jason Orendorff-2
Yes. First, you have to have a JSContext*. Then, your SPPluginEntryFunc
would need to get the JavaScript-implemented function from somewhere. Maybe
it's a global function, and you can get it from your global object using
JS_GetProperty. Then, you have to convert `caller` and `selector` from C
strings to JS strings and store them in JS::RootedValues. Then you can use
JS::Call to call the JS function. Then handle errors appropriately.

None of this is exactly easy, but all the APIs exist.

-j


On Wed, Apr 27, 2016 at 11:13 AM, <[hidden email]> wrote:

> Hello,
>
> I have a C API to embed. There, it is some function needing a function as
> argument:
>
>
> typedef SPAPI SPErr (*SPPluginEntryFunc)( const char *caller, const char
> *selector, void *message );
>
> ...
>
> typedef struct SPPluginsSuite {
> ...
>         SPAPI SPErr (*GetPluginHostEntry)( SPPluginRef plugin,
> SPPluginEntryFunc *host );
> ....
> }
>
> Could this be achieved in SpiderMonkey by passing some javascript
> implemented function to the C API?
>
> Thank you.
> _______________________________________________
> dev-tech-js-engine mailing list
> [hidden email]
> https://lists.mozilla.org/listinfo/dev-tech-js-engine
>
_______________________________________________
dev-tech-js-engine mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-js-engine
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: pass function to C API

Mihai Dobrescu
In reply to this post by Mihai Dobrescu
On Thursday, April 28, 2016 at 1:44:32 AM UTC+3, Jason Orendorff wrote:

> Yes. First, you have to have a JSContext*. Then, your SPPluginEntryFunc
> would need to get the JavaScript-implemented function from somewhere. Maybe
> it's a global function, and you can get it from your global object using
> JS_GetProperty. Then, you have to convert `caller` and `selector` from C
> strings to JS strings and store them in JS::RootedValues. Then you can use
> JS::Call to call the JS function. Then handle errors appropriately.
>
> None of this is exactly easy, but all the APIs exist.
>
> -j
>
>
> On Wed, Apr 27, 2016 at 11:13 AM, <[hidden email]> wrote:
>
> > Hello,
> >
> > I have a C API to embed. There, it is some function needing a function as
> > argument:
> >
> >
> > typedef SPAPI SPErr (*SPPluginEntryFunc)( const char *caller, const char
> > *selector, void *message );
> >
> > ...
> >
> > typedef struct SPPluginsSuite {
> > ...
> >         SPAPI SPErr (*GetPluginHostEntry)( SPPluginRef plugin,
> > SPPluginEntryFunc *host );
> > ....
> > }
> >
> > Could this be achieved in SpiderMonkey by passing some javascript
> > implemented function to the C API?
> >
> > Thank you.
> > _______________________________________________
> > dev-tech-js-engine mailing list
> > [hidden email]
> > https://lists.mozilla.org/listinfo/dev-tech-js-engine
> >

Hi, thank you.

I have been detained by other issues and I had to postpone this, but I have returned to it now.

My need is to embed scripting in Illustrator, where I should write a function in javascript, then match it against the mentioned c++ signature, transform it as a c++ type reference and pass it to a C function call.

Would this be possible.
_______________________________________________
dev-tech-js-engine mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-js-engine
Loading...