ArgExprMethod

Applies to:Fast Math Parser
Class:uCalc.Callback
Returns the object instance of the expression that's passed as an argument to a uCalc.Callback function+++Example
Syntax
ArgExpr(Index)
Parameters
Index
Int32
Index of the given argument. Note that Index is 1-based; the Index for the first arg is 1 (not 0)
Returns
Returns parsed expression object with which you can call functions like Evaluate or Execute
Remarks
uCalc allows you to not only pass arguments by value or by reference. But it also lets you pass an argument by expression. When an expression is passed By Expression, the expresison is not evaluated before being passed. Instead a handle to the parsed expression is passed, allowing the callback to perform the evaluation.
Example 1: Evaluate an expression only during callback

Sub EvaluateCallbackCB(ByVal ExprPartPtr As IntPtr)
   Dim ExprPart As New uCalc.Callback(ExprPartPtr)
   Console.WriteLine(ExprPart.ArgExpr(1).Evaluate()) ' Returns 90
   Console.WriteLine(ExprPart.ArgExpr(2).EvaluateStr()) ' Returns "Hello There FRIENDS"
End Sub

Sub EvaluateCallback()
   uc.DefineFunction("f(ByExpr Ex, ByExpr ExStr As String)", uc.PinAddr(AddressOf EvaluateCallbackCB))
   uc.Eval("f(10+20*4, 'Hello' + ' There ' +UCase('Friends'))")
End Sub

          

static void EvaluateCallbackCB(IntPtr ExprPartPtr) {
   var ExprPart = New uCalc.Callback(ExprPartPtr);
   Console.WriteLine(ExprPart.ArgExpr(1).Evaluate()); // Returns 90;
   Console.WriteLine(ExprPart.ArgExpr(2).EvaluateStr()); // Returns "Hello There FRIENDS";
}

static void EvaluateCallback() {
   uc.DefineFunction("f(ByExpr Ex, ByExpr ExStr As String)", uc.PinAddr(EvaluateCallbackCB));
   uc.Eval("f(10+20*4, 'Hello' + ' There ' +UCase('Friends'))");
}

          

procedure EvaluateCallbackCB(ExprPartPtr: System.Pointer);
begin
   
//var ExprPart: uCalc.CreateCallback(ExprPartPtr);
   WriteLn(ExprPart.ArgExpr(1).Evaluate()); // Returns 90;
   WriteLn(ExprPart.ArgExpr(2).EvaluateStr()); // Returns 'Hello There FRIENDS';
End;

procedure EvaluateCallback();
begin
   
   uc.DefineFunction('f(ByExpr Ex, ByExpr ExStr As String)', EvaluateCallbackCB);
   uc.Eval('f(10+20*4, "Hello" + " There " +UCase("Friends"))');
End;

          

void _stdcall EvaluateCallbackCB(uCalcPtr ExprPartPtr) {
   auto ExprPart = uCalc::Callback(ExprPartPtr);
   cout << ExprPart.ArgExpr(1).Evaluate() << endl; // Returns 90;
   cout << ExprPart.ArgExpr(2).EvaluateStr() << endl; // Returns "Hello There FRIENDS";
}

void EvaluateCallback() {
   uc.DefineFunction("f(ByExpr Ex, ByExpr ExStr As String)", EvaluateCallbackCB);
   uc.Eval("f(10+20*4, 'Hello' + ' There ' +UCase('Friends'))");
}

          

static void EvaluateCallbackCB(uCalcPtr ExprPartPtr) {
   auto ExprPart = uCalc::Callback(ExprPartPtr);
   Console::WriteLine(ExprPart.ArgExpr(1).Evaluate()); // Returns 90;
   Console::WriteLine(ExprPart.ArgExpr(2).EvaluateStr()); // Returns "Hello There FRIENDS";
}

static void EvaluateCallback() {
   uc.DefineFunction("f(ByExpr Ex, ByExpr ExStr As String)", ucPinAddr(EvaluateCallbackCB));
   uc.Eval("f(10+20*4, 'Hello' + ' There ' +UCase('Friends'))");
}

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

Private Function ArgExpr__(ByVal ExprPartHandle As IntPtr,ByVal Index As Int32) As IntPtr
End Function
            
[DllImport(uCalcDLL, CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl, EntryPoint="ArgExpr")]

protected static extern IntPtr ArgExpr_(IntPtr ExprPartHandle, Int32 Index);
            
{DLLImport}function ArgExpr__(ExprPartHandle: System.Pointer;Index: Int32): System.Pointer; cdecl; external uCalcDLL name 'ArgExpr';

            
typedef uCalcPtr (* __ArgExpr)(void *ExprPartHandle, int32_t Index); 

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

static uCalcPtr ArgExpr_(void *  ExprPartHandle, Int32 Index);
            
See also
Prev | Next