ArgMethod
Parameters
Index
Int32
Index of the given argument. Note that
Index is 1-based; the
Index for the first arg is 1 (not 0)
Example 1: Sending arguments to a callback function
Sub AreaCB(ByVal ExprPartPtr As IntPtr)
Dim ExprPart As New uCalc.Callback(ExprPartPtr)
ExprPart.ReturnDbl(ExprPart.Arg(1) * ExprPart.Arg(2))
End Sub
Sub Area()
uc.DefineFunction("Area(x, y)", uc.PinAddr(AddressOf AreaCB))
Console.WriteLine(uc.Eval("Area(3, 4)"))
End Sub
static void AreaCB(IntPtr ExprPartPtr) {
var ExprPart = New uCalc.Callback(ExprPartPtr);
ExprPart.Return(ExprPart.Arg(1) * ExprPart.Arg(2));
}
static void Area() {
uc.DefineFunction("Area(x, y)", uc.PinAddr(AreaCB));
Console.WriteLine(uc.Eval("Area(3, 4)"));
}
procedure AreaCB(ExprPartPtr: System.Pointer);
begin
ExprPart.Return(ExprPart.Arg(1) * ExprPart.Arg(2));
End;
procedure Area();
begin
uc.DefineFunction('Area(x, y)', AreaCB);
WriteLn(uc.Eval('Area(3, 4)'));
End;
void _stdcall AreaCB(uCalcPtr ExprPartPtr) {
auto ExprPart = uCalc::Callback(ExprPartPtr);
ExprPart.Return(ExprPart.Arg(1) * ExprPart.Arg(2));
}
void Area() {
uc.DefineFunction("Area(x, y)", AreaCB);
cout << uc.Eval("Area(3, 4)") << endl;
}
static void AreaCB(uCalcPtr ExprPartPtr) {
auto ExprPart = uCalc::Callback(ExprPartPtr);
ExprPart.Return(ExprPart.Arg(1) * ExprPart.Arg(2));
}
static void Area() {
uc.DefineFunction("Area(x, y)", ucPinAddr(AreaCB));
Console::WriteLine(uc.Eval("Area(3, 4)"));
}
Example 2: 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)"));
}
DLL import code
<DllImport(uCalcDLL, CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Cdecl, EntryPoint:="Arg")> _
Private Function Arg__(ByVal ExprPartHandle As IntPtr,ByVal Index As Int32) As Double
End Function
[DllImport(uCalcDLL, CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl, EntryPoint="Arg")]
protected static extern double Arg_(IntPtr ExprPartHandle, Int32 Index);
{DLLImport}function Arg__(ExprPartHandle: System.Pointer;Index: Int32): Double; cdecl; external uCalcDLL name 'Arg';
typedef double (* __Arg)(void *ExprPartHandle, int32_t Index);
[DllImport(uCalcLib, CharSet=CharSet::Ansi, CallingConvention=CallingConvention::Cdecl, EntryPoint = "Arg")]
static double Arg_(void * ExprPartHandle, Int32 Index);