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

using namespace std;
using namespace uCalcSoftware;

void ucalc_call Assert(uCalcBase::Callback cb) {
   auto condition = cb.ArgBool(1);

   // If the condition is false, then we evaluate the message expression
   if (condition == false) {
      auto errorMessage = cb.ArgExpr(2);
      cout << "Assertion failed: " << errorMessage.EvaluateStr() << endl;
   }
}
int main() {
   uCalc uc;
   uc.DefineVariable("x = 50");

   // The message is passed as an unevaluated expression
   uc.DefineFunction("Assert(condition As Bool, ByExpr message As String)", Assert);

   // This will do nothing because the condition is true
   uc.Eval("Assert(10 < 20, 'This will not be evaluated')");

   // This will trigger the assertion and evaluate the message expression
   uc.Eval("Assert(x > 100, 'x (' + Str(x) + ') is not greater than 100')");
}