ref: 0b9d3be3d0b4371c44142021040fb0ff03b03c29
parent: 08276111f575ac6142e922d62aa264dc1f30b69e
author: Tor Andersson <tor.andersson@artifex.com>
date: Wed Dec 16 06:49:52 EST 2015
Remove 'report' argument from js_dostring.
--- a/docs/examples.html
+++ b/docs/examples.html
@@ -19,7 +19,7 @@
char line[256];
js_State *J = js_newstate(NULL, NULL, JS_STRICT);
while (fgets(line, sizeof line, stdin))
- js_dostring(J, line, 1);
+ js_dostring(J, line);
js_freestate(J);
}
</pre>
@@ -44,7 +44,7 @@
js_newcfunction(J, hello, 1);
js_setglobal(J, "hello");
- js_dostring(J, "hello('world');", 0);
+ js_dostring(J, "hello('world');");
js_freestate(J);
}
--- a/docs/reference.html
+++ b/docs/reference.html
@@ -244,13 +244,12 @@
There are two convenience functions for loading and executing code.
<pre>
-int js_dostring(js_State *J, const char *source, int report);
+int js_dostring(js_State *J, const char *source);
</pre>
<p>
Compile and execute the script in the zero-terminated string in source argument.
If any errors occur, print the error message to stderr and return 1.
-If the report argument is non-zero, print the result of executing the script to stdout.
Return 0 on success.
<pre>
--- a/jsstate.c
+++ b/jsstate.c
@@ -125,7 +125,7 @@
js_endtry(J);
}
-int js_dostring(js_State *J, const char *source, int report)
+int js_dostring(js_State *J, const char *source)
{
if (js_try(J)) {
fprintf(stderr, "%s\n", js_tostring(J, -1));
@@ -135,9 +135,6 @@
js_loadstring(J, "[string]", source);
js_pushglobal(J);
js_call(J, 0);
- if (report)
- if (js_isdefined(J, -1))
- printf("%s\n", js_tostring(J, -1));
js_pop(J, 1);
js_endtry(J);
return 0;
--- a/main.c
+++ b/main.c
@@ -119,6 +119,23 @@
"require.cache = Object.create(null);\n"
;
+int eval_print(js_State *J, const char *source)
+{
+ if (js_ploadstring(J, "[string]", source)) {
+ fprintf(stderr, "%s\n", js_tostring(J, -1));
+ return 1;
+ }
+ js_pushglobal(J);
+ if (js_pcall(J, 0)) {
+ fprintf(stderr, "%s\n", js_tostring(J, -1));
+ return 1;
+ }
+ if (js_isdefined(J, -1))
+ printf("%s\n", js_tostring(J, -1));
+ js_pop(J, 1);
+ return 0;
+}
+
int
main(int argc, char **argv)
{
@@ -149,7 +166,7 @@
js_newcfunction(J, jsB_quit, "quit", 1);
js_setglobal(J, "quit");
- js_dostring(J, require_js, 0);
+ js_dostring(J, require_js);
if (argc > 1) {
for (i = 1; i < argc; ++i) {
@@ -160,7 +177,7 @@
} else {
fputs(PS1, stdout);
while (fgets(line, sizeof line, stdin)) {
- js_dostring(J, line, 1);
+ eval_print(J, line);
fputs(PS1, stdout);
}
putchar('\n');
--- a/mujs.h
+++ b/mujs.h
@@ -39,7 +39,7 @@
void js_freestate(js_State *J);
void js_gc(js_State *J, int report);
-int js_dostring(js_State *J, const char *source, int report);
+int js_dostring(js_State *J, const char *source);
int js_dofile(js_State *J, const char *filename);
int js_ploadstring(js_State *J, const char *filename, const char *source);
int js_ploadfile(js_State *J, const char *filename);