Subj : Re: beginner question spidermonkey To : Sterling Bates From : Brendan Eich Date : Thu Sep 02 2004 07:12 pm Sterling Bates wrote: > (I just received this today, but the date was August 26...?) > > "marian simon" wrote in message > news:ch83nk$d741@ripley.netscape.com... > >>static JSBool getName (JSContext *cx, JSObject *obj, uintN argc, jsval >>*argv, jsval *rval) >>{ >>char *name; >> >> name=ele->get_name(); //not good ?? >> printf("get_Name() name = %s obj=0x%x argc=%d \n",name,obj,argc); >> >>return JS_TRUE; >>} I'm not sure what was intended here, but I am concerned that beginners at C programming not also try to learn SpiderMonkey at the same time. I don't mean that harshly -- it's really not in any C beginner's best interest (although shaver claims he was learning C when he was learning SpiderMonkey). > I'm not sure if this is a typo, but you're not setting *rval to the actual > name. Brendan'll correct me if I'm wrong, but you probably want this: > > JSString *str; > str = JS_NewString(cx, name, strlen(name)); Check str here, return false if null. > *rval = STRING_TO_JSVAL(str); > > strlen() may not be right, but I don't recall C[++]'s string length function > :) Also, it may not be right to create a new JSString for every function > call, but aside from making that a property of the object I don't know any C > solutions. OTOH, Sterling IIRC knows Object-Pascal but not too much C, and has managed to hack an Obj-Pascal bridge to SpiderMonkey. Maybe my advice to beginners is not sound. ;-) /be .