Sorry the last was posted really badly, here it is cleaned up!

"Richard" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> I'm not the most familar with the SpiderMonkey docs, but I think they have 
> class handling functions, anyway to expose a function I do the following :
> (These links can help get you in the right direction too : 
> http://www.mozilla.org/js/spidermonkey/
> http://www.mozilla.org/js/spidermonkey/apidoc/gen/api-JS_DefineFunction.html )

Create the function definition (in C or C++):

JSBool MyFunction(JSContext *cx, JSObject *obj, uintN /* argc*/, jsval*argv, 
jsval * /*rval*/)
{
    //Do some stuff here ...
    //example to get two string values passed to you from Javascript :
    CAtlString 
arg1=CAtlString(JS_GetStringBytes(JS_ValueToString(cx,argv[0])));
    CAtlString arg2 = 
CAtlString(JS_GetStringBytes(JS_ValueToString(cx,argv[1])));
}
argc I believe is the number of args, argv is the data passed in, and 
rvalueis if you want to return a value to javascript.

you then pass the function to Javascript with the following :

JS_DefineFunction(cx,pJobj,"MyFunctionName",MyFunction,2,0);

cx and pJobj are the context and Global object you can get from 
thensIScriptContext, next is the name the function will appear as 
injavascript. then your function pointer, # of args the function takes, I 
believe the last param is always zero,

Hope that helps you going the right direction

--Richard 


_______________________________________________
dev-embedding mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-embedding

Reply via email to