Re: How can I evaluate code?
"H. William Welliver III" <[email protected]> Thu, 25 Apr 2019 10:03:38 -0400
| Newsgroups | gmane.comp.lang.pike.user |
|---|---|
| Message-ID | <[email protected]> |
You can use compile_string() to compile a string that contains a method constructed by you that contains the input you received, wrapped in a method. The simplest version of this might be:
program p = compile_string(“mixed runIt(){ return “ + myinput + “; }”);
mixed result = p()->runIt();
Since you are constructing the class around the input, and indeed the function that’s being evaluated, you can pass whatever you want to it.
Bill