-
Notifications
You must be signed in to change notification settings - Fork 353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Creating a function? #143
Comments
Well I think I got somewhere. Here it is: (remember that this is node)
OR, to actually run it in a function (so that 38472384 already written calculators don't have to be rewritten since they use
Sounds OK doesn't it? The code itself doesn't have anything extra except the very first line; so, any errors will give out the right line... |
A better approach is to put the values you want to pass into variables in the global scope: var a = /* ... */, b = /* ... */;
var myInterpreter = new Interpreter('a + b');
myInterpreter.setValueToScope('a', myInterpreter.nativeToPseudo(a));
myInterpreter.setValueToScope('b', myInterpreter.nativeToPseudo(b));
myInterpreter.run();
var r = myInterpreter.pseudoToNative(myInterpreter.value); Of course if you want to treat user-supplied code as the body of a function (so the user can use var userCode = /* ... */;
var code = '(function(a, b) {' + userCode + '})(a, b)';
var myInterpreter = new Interpreter(code);
/* ... */ |
Hey... just one note: neither of them are documented. Or did I miss them? |
Hi,
Is it possible to create a function, and then run the interpreter while passing arguments to the created function?
I need to replicate this:
But without using
new Function
(which is obviously an eval)I "kind of" managed by writing a function that creates the string that defines the function and passes it the params:
However, one of the parameters is a rather large object, and it messses up the code.
Is there a way to create a function and then pass it parameters directly from the API, rather than just evaluate code?
THANK YOU!!!
The text was updated successfully, but these errors were encountered: