ArgStrMethod

Applies to:Fast Math Parser
Class:uCalc.Callback
Returns the value being passed as argument in to a uCalc.Callback function in form of a string
Syntax
ArgStr(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: String
Returns the value being passed as argument in to a uCalc.Callback function in form of a string
Remarks
In addition to returning an argument that was passed as a string, ArgStr has the special property of returning an argument that was passed as any data type. If the argument was not a string, ArgStr converts it to a string before returning its value.
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:="ArgStr")> _

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

protected static extern  IntPtr ArgStr_(IntPtr ExprPartHandle, Int32 Index);
            
{DLLImport}function ArgStr__(ExprPartHandle: System.Pointer;Index: Int32):  PAnsiChar; cdecl; external uCalcDLL name 'ArgStr';

            
typedef const char * (* __ArgStr)(void *ExprPartHandle, int32_t Index); 

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

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