Skip to content
Snippets Groups Projects
Commit 9ea77f72 authored by rswindell's avatar rswindell
Browse files

write() now returns the string passed (instead of void).

Created writeln() method (with print as alias).
parent 577ef6da
No related branches found
No related tags found
No related merge requests found
......@@ -389,7 +389,7 @@ static JSBool
js_write(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
uintN i;
JSString * str;
JSString* str=NULL;
FILE* fp;
if((fp=(FILE*)JS_GetContextPrivate(cx))==NULL)
......@@ -402,11 +402,30 @@ js_write(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
fprintf(fp,"%s",JS_GetStringBytes(str));
}
if(str==NULL)
*rval = JSVAL_VOID;
else
*rval = STRING_TO_JSVAL(str);
return(JS_TRUE);
}
static JSBool
js_writeln(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
FILE* fp;
if((fp=(FILE*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
js_write(cx,obj,argc,argv,rval);
fprintf(fp,"\r\n");
return(JS_TRUE);
}
static JSFunctionSpec js_global_functions[] = {
{"write", js_write, 1}, /* write to HTML file */
{"writeln", js_writeln, 1}, /* write to HTML file */
{"print", js_writeln, 1}, /* alias for writeln */
{0}
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment