#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

#define tf(IsTrue) ((IsTrue) ? "True" : "False")

void ucalc_call MyFunc(uCalcBase::Callback cb) {
   // This error occurs during evaluation, not parsing.
   cb.Error().Raise("Manual evaluation failure!");
}

void ucalc_call MyHandler(Handle_uCalc h) {
   auto uc = uCalc(h);
   cout << "Handler triggered for error: " << uc.Error().Message() << endl;
   cout << "ErrorExpression() returned: '" << uc.Error().Expression() << "'" << endl;
   cout << "Is expression empty? " << tf(uc.Error().Expression() == "") << endl;
}

int main() {
   uCalc uc;
   uc.DefineFunction("MyFunc()", MyFunc);
   uc.Error().AddHandler(MyHandler);

   // The expression 'MyFunc()' itself is valid syntactically.
   cout << uc.EvalStr("MyFunc()") << endl;
}