diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2016-04-25 15:50:44 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2016-04-26 15:12:57 +0200 |
commit | 47fb8ab2dd34e0adc60f415c2ebe58b18f1a5e8b (patch) | |
tree | 75c117f1e1377f2d824a0d25c2ab4a0b0465672d /source | |
parent | a2f62569da0bb87b9d4c4d54e51d43be63ceb968 (diff) | |
download | mupdf-47fb8ab2dd34e0adc60f415c2ebe58b18f1a5e8b.tar.xz |
murun: Print result of evaluating a line in interactive mode.
Diffstat (limited to 'source')
-rw-r--r-- | source/tools/murun.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/source/tools/murun.c b/source/tools/murun.c index 03e092f7..eba987bb 100644 --- a/source/tools/murun.c +++ b/source/tools/murun.c @@ -23,6 +23,25 @@ static void *alloc(void *actx, void *ptr, unsigned int n) return fz_malloc_array(ctx, n, 1); } +static int eval_print(js_State *J, const char *source) +{ + if (js_ploadstring(J, "[string]", source)) { + fprintf(stderr, "%s\n", js_tostring(J, -1)); + js_pop(J, 1); + return 1; + } + js_pushglobal(J); + if (js_pcall(J, 0)) { + fprintf(stderr, "%s\n", js_tostring(J, -1)); + js_pop(J, 1); + return 1; + } + if (js_isdefined(J, -1)) + printf("%s\n", js_tostring(J, -1)); + js_pop(J, 1); + return 0; +} + static void jsB_propfun(js_State *J, const char *name, js_CFunction cfun, int n) { const char *realname = strchr(name, '.'); @@ -3174,7 +3193,7 @@ int murun_main(int argc, char **argv) char line[256]; fputs(PS1, stdout); while (fgets(line, sizeof line, stdin)) { - js_dostring(J, line); + eval_print(J, line); fputs(PS1, stdout); } putchar('\n'); |