Demonstrates defining a function that is implemented by a native callback in the host application.

ID: 297

				
					using uCalcSoftware;

var uc = new uCalc();

static void MyAreaCallback(uCalc.Callback cb) {
   var length = cb.Arg(1);
   var width = cb.Arg(2);
   cb.Return(length * width);
}


// The signature is defined, but the logic is provided by 'MyAreaCallback'.
uc.DefineFunction("Area(x, y)", MyAreaCallback);
Console.WriteLine(uc.Eval("Area(3, 4)"));
				
			
12
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

void ucalc_call MyAreaCallback(uCalcBase::Callback cb) {
   auto length = cb.Arg(1);
   auto width = cb.Arg(2);
   cb.Return(length * width);
}

int main() {
   uCalc uc;
   // The signature is defined, but the logic is provided by 'MyAreaCallback'.
   uc.DefineFunction("Area(x, y)", MyAreaCallback);
   cout << uc.Eval("Area(3, 4)") << endl;
}
				
			
12
				
					Imports System
Imports uCalcSoftware
Public Module Program
   
   Public Sub MyAreaCallback(ByVal cb As uCalc.Callback)
      Dim length = cb.Arg(1)
      Dim width = cb.Arg(2)
      cb.Return(length * width)
   End Sub
   
   Public Sub Main()
      Dim uc As New uCalc()
      '// The signature is defined, but the logic is provided by 'MyAreaCallback'.
      uc.DefineFunction("Area(x, y)", AddressOf MyAreaCallback)
      Console.WriteLine(uc.Eval("Area(3, 4)"))
   End Sub
End Module
				
			
12