ArgAddrMethod

Applies to:Fast Math Parser
Class:uCalc.Callback
Returns the address of the argument value that is being passed
Syntax
ArgAddr(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: IntPtr
Returns the address of the argument value that is being passed
Remarks
In addition to Arg which returns arguments that are of the default Double floating point numeric type, there are specialized functions for other datatypes such as ArgInt32, ArgInt64, etc. However, if the argument is of a data type that does not have a specialized function, you can retrieve the address of the argument value as a Pointer, and use that to retrieve the value.
Example 1: Dealing with various data types in a callback

Sub MyFunctionCB(ByVal ExprPartPtr As IntPtr)
   Dim ExprPart As New uCalc.Callback(ExprPartPtr)
   Dim ucc = ExprPart.GetuCalc()

   Console.WriteLine(ExprPart.ArgInt32(1)) ' Returns 1230
   Console.WriteLine(ExprPart.ArgInt64(2)) ' Returns 2

   Console.WriteLine(ucc.GetItemOf("Int8").GetDataType().ToString(ExprPart.ArgAddr(3))) ' Returns -1
   Console.WriteLine(ucc.GetItemOf("Int").GetDataType().ToString(ExprPart.ArgPtr(4))) ' Returns 123
End Sub

Sub MyFunctionCallback()
   uc.DefineVariable("x As Int = 123")
   uc.DefineVariable("xPtr As Int Ptr = AddressOf(x)")
   uc.DefineFunction("MyFunc(a As Int32, b As Int64, c As Byte, d As Int Ptr)", uc.PinAddr(AddressOf MyFunctionCB))
   uc.Eval("MyFunc(x*10, 1+1, 255, xPtr)")
End Sub

          

static void MyFunctionCB(IntPtr ExprPartPtr) {
   var ExprPart = New uCalc.Callback(ExprPartPtr);
   var ucc = ExprPart.GetuCalc();
   
   Console.WriteLine(ExprPart.ArgInt32(1)); // Returns 1230;
   Console.WriteLine(ExprPart.ArgInt64(2)); // Returns 2;
   
   Console.WriteLine(ucc.GetItemOf("Int8").GetDataType().ToString(ExprPart.ArgAddr(3))); // Returns -1;
   Console.WriteLine(ucc.GetItemOf("Int").GetDataType().ToString(ExprPart.ArgPtr(4))); // Returns 123;
}

static void MyFunctionCallback() {
   uc.DefineVariable("x As Int = 123");
   uc.DefineVariable("xPtr As Int Ptr = AddressOf(x)");
   uc.DefineFunction("MyFunc(a As Int32, b As Int64, c As Byte, d As Int Ptr)", uc.PinAddr(MyFunctionCB));
   uc.Eval("MyFunc(x*10, 1+1, 255, xPtr)");
}

          

procedure MyFunctionCB(ExprPartPtr: System.Pointer);
begin
   
//var ExprPart: uCalc.CreateCallback(ExprPartPtr);
//var ucc = ExprPart.GetuCalc();

   WriteLn(ExprPart.ArgInt32(1)); // Returns 1230;
   WriteLn(ExprPart.ArgInt64(2)); // Returns 2;

   WriteLn(ucc.GetItemOf('Int8').GetDataType().ToString(ExprPart.ArgAddr(3))); // Returns -1;
   WriteLn(ucc.GetItemOf('Int').GetDataType().ToString(ExprPart.ArgPtr(4))); // Returns 123;
End;

procedure MyFunctionCallback();
begin
   
   uc.DefineVariable('x As Int = 123');
   uc.DefineVariable('xPtr As Int Ptr = AddressOf(x)');
   uc.DefineFunction('MyFunc(a As Int32, b As Int64, c As Byte, d As Int Ptr)', MyFunctionCB);
   uc.Eval('MyFunc(x*10, 1+1, 255, xPtr)');
End;

          

void _stdcall MyFunctionCB(uCalcPtr ExprPartPtr) {
   auto ExprPart = uCalc::Callback(ExprPartPtr);
   auto ucc = ExprPart.GetuCalc();
   
   cout << ExprPart.ArgInt32(1) << endl; // Returns 1230;
   cout << ExprPart.ArgInt64(2) << endl; // Returns 2;
   
   cout << ucc.GetItemOf("Int8").GetDataType().ToString(ExprPart.ArgAddr(3)) << endl; // Returns -1;
   cout << ucc.GetItemOf("Int").GetDataType().ToString(ExprPart.ArgPtr(4)) << endl; // Returns 123;
}

void MyFunctionCallback() {
   uc.DefineVariable("x As Int = 123");
   uc.DefineVariable("xPtr As Int Ptr = AddressOf(x)");
   uc.DefineFunction("MyFunc(a As Int32, b As Int64, c As Byte, d As Int Ptr)", MyFunctionCB);
   uc.Eval("MyFunc(x*10, 1+1, 255, xPtr)");
}

          

static void MyFunctionCB(uCalcPtr ExprPartPtr) {
   auto ExprPart = uCalc::Callback(ExprPartPtr);
   auto ucc = ExprPart.GetuCalc();
   
   Console::WriteLine(ExprPart.ArgInt32(1)); // Returns 1230;
   Console::WriteLine(ExprPart.ArgInt64(2)); // Returns 2;
   
   Console::WriteLine(ucc.GetItemOf("Int8").GetDataType().ToString(ExprPart.ArgAddr(3))); // Returns -1;
   Console::WriteLine(ucc.GetItemOf("Int").GetDataType().ToString(ExprPart.ArgPtr(4))); // Returns 123;
}

static void MyFunctionCallback() {
   uc.DefineVariable("x As Int = 123");
   uc.DefineVariable("xPtr As Int Ptr = AddressOf(x)");
   uc.DefineFunction("MyFunc(a As Int32, b As Int64, c As Byte, d As Int Ptr)", ucPinAddr(MyFunctionCB));
   uc.Eval("MyFunc(x*10, 1+1, 255, xPtr)");
}

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

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

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

            
typedef  void * (* __ArgAddr)(void *ExprPartHandle, int32_t Index); 

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

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