#include #include "uCalc.h" using namespace std; using namespace uCalcSoftware; // This error handler allows you to use variables that were not // explicitly defined previously by defining unrecognized identifiers // as variables instead of returning an error. void ucalc_call AutoVariableDef(Handle_uCalc h) { auto uc = uCalc(h); if (uc.Error().Code() == ErrorCode::Undefined_Identifier) { uc.DefineVariable(uc.Error().Symbol()); uc.Error().Response(ErrorHandlerResponse::Resume); } } int main() { uCalc uc; uc.Error().AddHandler(AutoVariableDef); // The handler will automatically define 'AutoTest' on first use. cout << uc.Eval("AutoTest = 123") << endl; cout << uc.Eval("AutoTest * 1000") << endl; }