ReturnMethod

Applies to:Fast Math Parser
Class:uCalc.Callback
Sets the return value (default floating point) of a uCalc.Callback function
Syntax
Return(Value)
Parameters
Value
double
Floating point value that your callback returns
Returns
Nothing
Remarks
When you define a callback function with DefineFunction and you want to return a floating point number, do it with Return.

Note: For compilers in which Return is a reserved keyword, use ReturnDbl instead.

Example 1: Sending arguments to a callback function

Sub AreaCB(ByVal ExprPartPtr As IntPtr)
   Dim ExprPart As New uCalc.Callback(ExprPartPtr)
   ExprPart.ReturnDbl(ExprPart.Arg(1) * ExprPart.Arg(2))
End Sub

Sub Area()
   uc.DefineFunction("Area(x, y)", uc.PinAddr(AddressOf AreaCB))
   Console.WriteLine(uc.Eval("Area(3, 4)")) ' Returns 12
End Sub

          

static void AreaCB(IntPtr ExprPartPtr) {
   var ExprPart = New uCalc.Callback(ExprPartPtr);
   ExprPart.Return(ExprPart.Arg(1) * ExprPart.Arg(2));
}

static void Area() {
   uc.DefineFunction("Area(x, y)", uc.PinAddr(AreaCB));
   Console.WriteLine(uc.Eval("Area(3, 4)")); // Returns 12;
}

          

procedure AreaCB(ExprPartPtr: System.Pointer);
begin
   
//var ExprPart: uCalc.CreateCallback(ExprPartPtr);
   ExprPart.Return(ExprPart.Arg(1) * ExprPart.Arg(2));
End;

procedure Area();
begin
   
   uc.DefineFunction('Area(x, y)', AreaCB);
   WriteLn(uc.Eval('Area(3, 4)')); // Returns 12;
End;

          

void _stdcall AreaCB(uCalcPtr ExprPartPtr) {
   auto ExprPart = uCalc::Callback(ExprPartPtr);
   ExprPart.Return(ExprPart.Arg(1) * ExprPart.Arg(2));
}

void Area() {
   uc.DefineFunction("Area(x, y)", AreaCB);
   cout << uc.Eval("Area(3, 4)") << endl; // Returns 12;
}

          

static void AreaCB(uCalcPtr ExprPartPtr) {
   auto ExprPart = uCalc::Callback(ExprPartPtr);
   ExprPart.Return(ExprPart.Arg(1) * ExprPart.Arg(2));
}

static void Area() {
   uc.DefineFunction("Area(x, y)", ucPinAddr(AreaCB));
   Console::WriteLine(uc.Eval("Area(3, 4)")); // Returns 12;
}

          
Example 2: Determining the number of arguments being passed to a callback function

Sub MyAverageCB(ByVal ExprPartPtr As IntPtr)
   Dim ExprPart As New uCalc.Callback(ExprPartPtr)
   Dim Total As double = 0

   Dim x As Int32
   for x = 1 To ExprPart.ArgCount()
      Total = Total + ExprPart.Arg(x)
   Next

   ExprPart.ReturnDbl(Total / ExprPart.ArgCount())
End Sub

Sub MyAverage()
   uc.DefineFunction("Average(x ...)", uc.PinAddr(AddressOf MyAverageCB))
   Console.WriteLine(uc.Eval("Average(10, 3, 7, 4)")) ' Returns 6
End Sub

          

static void MyAverageCB(IntPtr ExprPartPtr) {
   var ExprPart = New uCalc.Callback(ExprPartPtr);
   double Total = 0;
   
   for (Int32 x = 1; x <= ExprPart.ArgCount(); x++) {
      Total = Total + ExprPart.Arg(x);
   }
   
   ExprPart.Return(Total / ExprPart.ArgCount());
}

static void MyAverage() {
   uc.DefineFunction("Average(x ...)", uc.PinAddr(MyAverageCB));
   Console.WriteLine(uc.Eval("Average(10, 3, 7, 4)")); // Returns 6;
}

          

procedure MyAverageCB(ExprPartPtr: System.Pointer);
begin
   
//var ExprPart: uCalc.CreateCallback(ExprPartPtr);
//var Total: Double = 0;

   for x := 1 to ExprPart.ArgCount() do
begin
   Total = Total + ExprPart.Arg(x);
End;

   ExprPart.Return(Total / ExprPart.ArgCount());
End;

procedure MyAverage();
begin
   
   uc.DefineFunction('Average(x ...)', MyAverageCB);
   WriteLn(uc.Eval('Average(10, 3, 7, 4)')); // Returns 6;
End;

          

void _stdcall MyAverageCB(uCalcPtr ExprPartPtr) {
   auto ExprPart = uCalc::Callback(ExprPartPtr);
   double Total = 0;
   
   for (int x = 1; x <= ExprPart.ArgCount(); x++) {
      Total = Total + ExprPart.Arg(x);
   }
   
   ExprPart.Return(Total / ExprPart.ArgCount());
}

void MyAverage() {
   uc.DefineFunction("Average(x ...)", MyAverageCB);
   cout << uc.Eval("Average(10, 3, 7, 4)") << endl; // Returns 6;
}

          

static void MyAverageCB(uCalcPtr ExprPartPtr) {
   auto ExprPart = uCalc::Callback(ExprPartPtr);
   double Total = 0;
   
   for (int x = 1; x <= ExprPart.ArgCount(); x++) {
      Total = Total + ExprPart.Arg(x);
   }
   
   ExprPart.Return(Total / ExprPart.ArgCount());
}

static void MyAverage() {
   uc.DefineFunction("Average(x ...)", ucPinAddr(MyAverageCB));
   Console::WriteLine(uc.Eval("Average(10, 3, 7, 4)")); // Returns 6;
}

          
DLL import code
<DllImport(uCalcDLL, CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Cdecl, EntryPoint:="Return")> _

Private Sub Return__(ByVal ExprPartHandle As IntPtr,ByVal Value As Double)
End Sub
            
[DllImport(uCalcDLL, CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl, EntryPoint="Return")]

protected static extern  void Return_(IntPtr ExprPartHandle, double Value);
            
{DLLImport}procedure Return__(ExprPartHandle: System.Pointer;Value: Double); cdecl; external uCalcDLL name 'Return';

            
typedef  void (* __Return)(void *ExprPartHandle, double Value); 

            
[DllImport(uCalcLib, CharSet=CharSet::Ansi, CallingConvention=CallingConvention::Cdecl, EntryPoint = "Return")]

static void Return_(void *  ExprPartHandle, double Value);
            
See also
Prev | Next