From e5b9aff9b99ea007f4c047d13ebaab6aadcca403 Mon Sep 17 00:00:00 2001 From: Hauke D Date: Mon, 13 Aug 2018 21:02:41 +0200 Subject: [PATCH] Create a generic function for calling Perl subs Previously, each call to a Perl sub would "eval" a bunch of JS code, this allows simplification of that "eval" by providing Perl.dispatch, on which a JS "bind" can be done. --- web/webperl.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/web/webperl.js b/web/webperl.js index 08d77c8..39d161e 100644 --- a/web/webperl.js +++ b/web/webperl.js @@ -32,6 +32,20 @@ var Perl = { state: "Uninitialized", readyCallback: null, stdout_buf: "", stderr_buf: "", // for our default Perl.output implementation + dispatch: function (perl) { + Perl._call_code_args = Array.prototype.slice.call(arguments, 1); + Perl.eval(perl); + if (Perl._call_code_error) { + var err = Perl._call_code_error; + delete Perl._call_code_error; + throw err; + } + else { + var rv = Perl._call_code_rv; + delete Perl._call_code_rv; + return rv; + } + }, }; /* TODO: Embedded script should be able to influence the running of Perl,