Re: pass function to C API
Mihai Dobrescu <[email protected]> Sun, 22 Jan 2017 04:50:44 -0800 (PST)
| Newsgroups | gmane.comp.mozilla.devel.jseng |
|---|---|
| Message-ID | <[email protected]> |
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, <[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 > > 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.