ArgCountMethod
Returns the number of arguments being passed to a
uCalc.Callback function
Example 1: 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)"))
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)"));
}
procedure MyAverageCB(ExprPartPtr: System.Pointer);
begin
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)'));
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;
}
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)"));
}
Example 2: 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
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());
}
}
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
for x := 1 to ExprPart.ArgCount() do
begin
WriteLn(ExprPart.ArgStr(x) + ' Type: ' + ExprPart.ArgObj(x).GetDataType().Name());
End;
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;
}
}
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());
}
}
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:="ArgCount")> _
Private Function ArgCount__(ByVal ExprPartHandle As IntPtr) As Int32
End Function
[DllImport(uCalcDLL, CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl, EntryPoint="ArgCount")]
protected static extern Int32 ArgCount_(IntPtr ExprPartHandle);
{DLLImport}function ArgCount__(ExprPartHandle: System.Pointer): Int32; cdecl; external uCalcDLL name 'ArgCount';
typedef int32_t (* __ArgCount)(void *ExprPartHandle);
[DllImport(uCalcLib, CharSet=CharSet::Ansi, CallingConvention=CallingConvention::Cdecl, EntryPoint = "ArgCount")]
static Int32 ArgCount_(void * ExprPartHandle);