ArgObjMethod

Applies to:Fast Math Parser
Class:uCalc.Callback
Returns an object instance of the argument being passed to a uCalc.Callback function
Syntax
ArgObj(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
Type: Item
The returned object can be used (where relevent) just like any other uCalc.Item
Remarks
Each argument is a uCalc.Item, just like anything else defined with Define. With this object, you can do such things as determine the argument's data type, determine which instance of uCalc it belongs to, retrieve the Pointer of the value of the argument, etc.
Example 1: Displaying the data types of arguments when the data types are not known in advance

Sub DisplayArgsCB(ByVal ExprPartPtr As IntPtr)
   Dim ExprPart As New uCalc.Callback(ExprPartPtr)
   Dim x As Int32
   for x = 1 To ExprPart.ArgCount()
      Console.WriteLine(ExprPart.ArgStr(x) + "  Type: " + ExprPart.ArgObj(x).GetDataType().Name())
   Next
   ' Output
   ' 5  Type: double
   ' 3+2i  Type: complex
   ' Hello  Type: string
   ' true  Type: bool
   ' false  Type: bool
   ' 9  Type: int16
End Sub

Sub DisplayArgs()
   uc.DefineFunction("DisplayArgs(Arg As AnyType ...)", uc.PinAddr(AddressOf DisplayArgsCB))
   uc.Eval("DisplayArgs(5, 3+2*#i, 'Hello', True, False, Int16(5+4.1))")
End Sub

          

static void DisplayArgsCB(IntPtr ExprPartPtr) {
   var ExprPart = New uCalc.Callback(ExprPartPtr);
   for (Int32 x = 1; x <= ExprPart.ArgCount(); x++) {
      Console.WriteLine(ExprPart.ArgStr(x) + "  Type: " + ExprPart.ArgObj(x).GetDataType().Name());
   }
   // Output
   // 5  Type: double
   // 3+2i  Type: complex
   // Hello  Type: string
   // true  Type: bool
   // false  Type: bool
   // 9  Type: int16
   
}

static void DisplayArgs() {
   uc.DefineFunction("DisplayArgs(Arg As AnyType ...)", uc.PinAddr(DisplayArgsCB));
   uc.Eval("DisplayArgs(5, 3+2*#i, 'Hello', True, False, Int16(5+4.1))");
}

          

procedure DisplayArgsCB(ExprPartPtr: System.Pointer);
begin
   
//var ExprPart: uCalc.CreateCallback(ExprPartPtr);
   for x := 1 to ExprPart.ArgCount() do
begin
   WriteLn(ExprPart.ArgStr(x) + '  Type: ' + ExprPart.ArgObj(x).GetDataType().Name());
End;
   // Output
// 5  Type: double
// 3+2i  Type: complex
// Hello  Type: string
// true  Type: bool
// false  Type: bool
// 9  Type: int16

End;

procedure DisplayArgs();
begin
   
   uc.DefineFunction('DisplayArgs(Arg As AnyType ...)', DisplayArgsCB);
   uc.Eval('DisplayArgs(5, 3+2*#i, "Hello", True, False, Int16(5+4.1))');
End;

          

void _stdcall DisplayArgsCB(uCalcPtr ExprPartPtr) {
   auto ExprPart = uCalc::Callback(ExprPartPtr);
   for (int x = 1; x <= ExprPart.ArgCount(); x++) {
      cout << ExprPart.ArgStr(x) << "  Type: " << ExprPart.ArgObj(x).GetDataType().Name() << endl;
   }
   // Output
   // 5  Type: double
   // 3+2i  Type: complex
   // Hello  Type: string
   // true  Type: bool
   // false  Type: bool
   // 9  Type: int16
   
}

void DisplayArgs() {
   uc.DefineFunction("DisplayArgs(Arg As AnyType ...)", DisplayArgsCB);
   uc.Eval("DisplayArgs(5, 3+2*#i, 'Hello', True, False, Int16(5+4.1))");
}

          

static void DisplayArgsCB(uCalcPtr ExprPartPtr) {
   auto ExprPart = uCalc::Callback(ExprPartPtr);
   for (int x = 1; x <= ExprPart.ArgCount(); x++) {
      Console::WriteLine(ExprPart.ArgStr(x) + "  Type: " + ExprPart.ArgObj(x).GetDataType().Name());
   }
   // Output
   // 5  Type: double
   // 3+2i  Type: complex
   // Hello  Type: string
   // true  Type: bool
   // false  Type: bool
   // 9  Type: int16
   
}

static void DisplayArgs() {
   uc.DefineFunction("DisplayArgs(Arg As AnyType ...)", ucPinAddr(DisplayArgsCB));
   uc.Eval("DisplayArgs(5, 3+2*#i, 'Hello', True, False, Int16(5+4.1))");
}

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

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

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

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

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

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