Subj : Re: Executing a line of C code in javascript To : netscape.public.mozilla.jseng From : David Bradley Date : Thu Aug 21 2003 05:46 pm Heath Raftery wrote: > I noticed that previously in comp.lang.javascript, people have claimed > that C++/C functions are tricky to execute in javascript, possibly > requiring ActiveX interfaces or JNI work. However, Mozilla seems to do > it fine. Sounds like they're talking about Java not JavaScript > So, how would I achieve this without including most of mozilla in my > application? Is there a simpler way of achieving the same? I just want > to resolve a host name! Or even simpler - I just want to parse a PAC > file! Do you have control over the code you're embedding SpiderMonkey in? What you need to do is to use JS_DefineFunction to link the C function to an object, possibly the global object. js.c has an example of what I'm talking about http://lxr.mozilla.org/seamonkey/source/js/src/js.c#2218. That defines multiple functions, JS_DefineFunction can be used to define a single function. I don't believe there's anything that would allow you to dynamically specify a native function at runtime. David Bradley .