Subj : Re: how to implement a function with JSString return value and To : netscape.public.mozilla.jseng From : Matthew Mondor Date : Mon May 16 2005 11:12 am On Mon, 16 May 2005 15:59:31 +0800 twmt wrote: > hello, everyone. > > I am using spidermonkey, and want to implenment such a javascript: > ...... > > .. ... > foo() is the native C function called from javscript. > > I want foo() return a string, so I define > JSString *foo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, > jsval *rval). and JS_DefineFunction(context, global, "foo", foo, 1, > 0); The return value of your C native function should be set using the jsval *rval pointer. A good example source is in the spidermonkey code itself, the way standard classes are implemented... For instance, if you already created a JSString, you can use: *rval = STRING_TO_JSVAL(string); where string consists of your JSString *. You are right that all prototypes should use a JSBool return type. Matt -- Note: Please only reply on the list since other mail is blocked by default. Private messages from your address can be allowed by first asking, however. .