JitCat

A C++17 library for parsing and executing expressions. Allows easy exposure of variables and functions from C++ through built-in reflection functionality. JitCat is currently being expanded into a more fully featured scripting language.

Get it on github.

Features

Usage example

#include <jitcat/Expression.h>
#include <jitcat/ExpressionAny.h>
using namespace jitcat;

//A simple floating point calculation
Expression<float> anExpression("2.0 * abs(21.0)");
anExpression.compile(nullptr);
float value = anExpression.getValue(nullptr);

//String addition
Expression<std::string> anotherExpression("\"Hello\" + \" World\"");
anotherExpression.compile(nullptr);
std::string message = anotherExpression.getValue(nullptr);

//An expression returning an object. It uses a context that contains variables that can be referenced inside the expression.
Expression<MyObject*> objectTypeExpression("anObject.member.list[42].getMyObject()");
objectTypeExpression.compile(myContext);
MyObject* objectResult = objectTypeExpression.getValue(myContext);

//An expression that accepts any return type, in this case it is a std::vector.
//Passing myContext to the constructor will call compile automatically.
ExpressionAny anyTypedExpression(myContext, "anObject.member.list");
std::any anyValue = anyTypedExpression.getValue(myContext);
if (anyTypedExpression.getType().isFloatType())
{
	float floatValue = std::any_cast<float>(anyValue);
	//Do something
}

Documentation

Building JitCat
Building LLVM for use with JitCat
See the the examples directory for a basic example.

Roadmap

JitCat is under active development. These are some of the major features that can be expected in the future:

License

Uses the permissive MIT license, see the included LICENSE file.

Author

Machiel van Hooren

Acknowledgements

Thanks to Ronimo Games, my ex-employer, for supporting and actively using this library. Many improvements have been made during office hours!