Remove 'report' argument from js_dostring.

This commit is contained in:
Tor Andersson
2015-12-16 11:49:52 +01:00
parent 08276111f5
commit 0b9d3be3d0
5 changed files with 24 additions and 11 deletions
+2 -2
View File
@@ -19,7 +19,7 @@ int main(int argc, char **argv)
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 @@ int main(int argc, char **argv)
js_newcfunction(J, hello, 1);
js_setglobal(J, "hello");
js_dostring(J, "hello('world');", 0);
js_dostring(J, "hello('world');");
js_freestate(J);
}
+1 -2
View File
@@ -244,13 +244,12 @@ In case of failure, return 1 with the error object on the stack.
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>
+1 -4
View File
@@ -125,7 +125,7 @@ void js_loadfile(js_State *J, const char *filename)
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 @@ int js_dostring(js_State *J, const char *source, int report)
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;
+19 -2
View File
@@ -119,6 +119,23 @@ static const char *require_js =
"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 @@ main(int argc, char **argv)
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 @@ main(int argc, char **argv)
} else {
fputs(PS1, stdout);
while (fgets(line, sizeof line, stdin)) {
js_dostring(J, line, 1);
eval_print(J, line);
fputs(PS1, stdout);
}
putchar('\n');
+1 -1
View File
@@ -39,7 +39,7 @@ js_Panic js_atpanic(js_State *J, js_Panic panic);
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);