Re: pass function to C API

Jason Orendorff <[email protected]>
Newsgroups gmane.comp.mozilla.devel.jseng
Message-ID <CA+W3DWFjASTG+nqduP3+Pwa70buML=zyrF3B6gT+YRXGXRrqUQ@mail.gmail.com>
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, <[email protected]> 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
> [email protected]
> https://lists.mozilla.org/listinfo/dev-tech-js-engine
>
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.