Addon for math function scripting for OF?

Can anyone suggest an addon or library that enables one to write simple math functions in a string and have them calculated? For example something like this:

string scriptTxt = "2.0 + 0.5 * sin(t)";
float result = parseScript(scriptTxt, ofGetElapsedTimef());

Basically, I want to have a text input box in my OF app where a user can input a simple maths function that is then calculated. Doesn’t have to be anything too complicated, just simple +,-,/*,sin,cos and handle brackets. Preferably fast, so I don’t want to call any external parser with ofSystem("") or python or anything like that.

The only thing I found was ofxLua but that seems a bit overly complicated for what I need.


I found ofxExpression which looks great, but it seems to only take a maximum of 3 variables as input? Not sure if i’m missing something.

.:: C++ Mathematical Expression Library (ExprTk) - By Arash Partow ::. is a nice (and fast) expression library.

i’ve used it a few times but did not manage to streamline things in an coherent addon (mostly because the use cases differ enough to make it difficult to provide a “universal” interface). but being header-only it’s pretty painless to drop in a project. a nice feature is being able to bind your own C++ functions into the expressions parser.

1 Like

i havent had the time to continue working on this, but you could add a javascript engine. v8, duktape, quick, …