Skip to content

Commit

Permalink
implemented eval()
Browse files Browse the repository at this point in the history
  • Loading branch information
kortenkamp committed Sep 5, 2022
1 parent 34d3b01 commit 8cb12c6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/js/libcs/Operators.js
Expand Up @@ -4372,6 +4372,23 @@ evaluator.self$0 = function (args, modifs) {
return Json._helper.self;
};

evaluator.eval$1 = function (args, modifs) {
Object.entries(modifs).forEach(function ([key, value]) {
let val = evaluate(value);
namespace.newvar(key);
namespace.setvar(key, val);
});

namespace.pushVstack("*");
const erg = evaluate(args[0]);
namespace.cleanVstack();
Object.entries(modifs).forEach(function ([key, value]) {
namespace.removevar(key);
});
return erg;
// return tt(args,modifs);
};

///////////////////////////////
// Calling external code //
///////////////////////////////
Expand Down
4 changes: 4 additions & 0 deletions tests/ColonOp_tests.js
Expand Up @@ -127,3 +127,7 @@ describe("Assign code to JSON objects", function () {
itCmd('obj={};obj:"code":=(x=x*7);x=1;obj.code;obj.code;x', "49");
itCmd('obj={};obj:"code":=(x=x*7);x=1;obj:"code";obj.code;x', "49");
});

describe("Calling code through eval", function () {
itCmd("eval(x+y,x->2,y->5)", "7");
});
2 changes: 1 addition & 1 deletion tests/JSON_tests.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8cb12c6

Please sign in to comment.