GetuCalcMethod
Returns the
uCalc instance the current expression part belongs to
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))
Console.WriteLine(ExprPart.ArgInt64(2))
Console.WriteLine(ucc.GetItemOf("Int8").GetDataType().ToString(ExprPart.ArgAddr(3)))
Console.WriteLine(ucc.GetItemOf("Int").GetDataType().ToString(ExprPart.ArgPtr(4)))
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));
Console.WriteLine(ExprPart.ArgInt64(2));
Console.WriteLine(ucc.GetItemOf("Int8").GetDataType().ToString(ExprPart.ArgAddr(3)));
Console.WriteLine(ucc.GetItemOf("Int").GetDataType().ToString(ExprPart.ArgPtr(4)));
}
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
WriteLn(ExprPart.ArgInt32(1));
WriteLn(ExprPart.ArgInt64(2));
WriteLn(ucc.GetItemOf('Int8').GetDataType().ToString(ExprPart.ArgAddr(3)));
WriteLn(ucc.GetItemOf('Int').GetDataType().ToString(ExprPart.ArgPtr(4)));
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;
cout << ExprPart.ArgInt64(2) << endl;
cout << ucc.GetItemOf("Int8").GetDataType().ToString(ExprPart.ArgAddr(3)) << endl;
cout << ucc.GetItemOf("Int").GetDataType().ToString(ExprPart.ArgPtr(4)) << endl;
}
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));
Console::WriteLine(ExprPart.ArgInt64(2));
Console::WriteLine(ucc.GetItemOf("Int8").GetDataType().ToString(ExprPart.ArgAddr(3)));
Console::WriteLine(ucc.GetItemOf("Int").GetDataType().ToString(ExprPart.ArgPtr(4)));
}
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)");
}
Example 2: Raising a floating point exception
Sub FPEnvRaiseTestCB(ByVal ExprPartPtr As IntPtr)
Dim ExprPart As New uCalc.Callback(ExprPartPtr)
ExprPart.GetuCalc().FPEnvRaiseException(FPEnvExceptionEnum.Invalid)
End Sub
Sub FPEnvRaiseTest()
uc.DefineFunction("FPEnvRaiseTest()", uc.PinAddr(AddressOf FPEnvRaiseTestCB))
Console.WriteLine(uc.EvalStr("FPEnvRaiseTest()"))
End Sub
static void FPEnvRaiseTestCB(IntPtr ExprPartPtr) {
var ExprPart = New uCalc.Callback(ExprPartPtr);
ExprPart.GetuCalc().FPEnvRaiseException(FPEnvExceptionEnum.Invalid);
}
static void FPEnvRaiseTest() {
uc.DefineFunction("FPEnvRaiseTest()", uc.PinAddr(FPEnvRaiseTestCB));
Console.WriteLine(uc.EvalStr("FPEnvRaiseTest()"));
}
procedure FPEnvRaiseTestCB(ExprPartPtr: System.Pointer);
begin
ExprPart.GetuCalc().FPEnvRaiseException(FPEnvExceptionEnum.Invalid);
End;
procedure FPEnvRaiseTest();
begin
uc.DefineFunction('FPEnvRaiseTest()', FPEnvRaiseTestCB);
WriteLn(uc.EvalStr('FPEnvRaiseTest()'));
End;
void _stdcall FPEnvRaiseTestCB(uCalcPtr ExprPartPtr) {
auto ExprPart = uCalc::Callback(ExprPartPtr);
ExprPart.GetuCalc().FPEnvRaiseException(FPEnvExceptionEnum::Invalid);
}
void FPEnvRaiseTest() {
uc.DefineFunction("FPEnvRaiseTest()", FPEnvRaiseTestCB);
cout << uc.EvalStr("FPEnvRaiseTest()") << endl;
}
static void FPEnvRaiseTestCB(uCalcPtr ExprPartPtr) {
auto ExprPart = uCalc::Callback(ExprPartPtr);
ExprPart.GetuCalc().FPEnvRaiseException(FPEnvExceptionEnum::Invalid);
}
static void FPEnvRaiseTest() {
uc.DefineFunction("FPEnvRaiseTest()", ucPinAddr(FPEnvRaiseTestCB));
Console::WriteLine(uc.EvalStr("FPEnvRaiseTest()"));
}
DLL import code
<DllImport(uCalcDLL, CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Cdecl, EntryPoint:="GetuCalc_Overload_Callback")> _
Private Function GetuCalc_Overload_Callback__(ByVal ExprPartHandle As IntPtr) As IntPtr
End Function
[DllImport(uCalcDLL, CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl, EntryPoint="GetuCalc_Overload_Callback")]
protected static extern IntPtr GetuCalc_Overload_Callback_(IntPtr ExprPartHandle);
{DLLImport}function GetuCalc_Overload_Callback__(ExprPartHandle: System.Pointer): System.Pointer; cdecl; external uCalcDLL name 'GetuCalc_Overload_Callback';
typedef uCalcPtr (* __GetuCalc_Overload_Callback)(void *ExprPartHandle);
[DllImport(uCalcLib, CharSet=CharSet::Ansi, CallingConvention=CallingConvention::Cdecl, EntryPoint = "GetuCalc_Overload_Callback")]
static uCalcPtr GetuCalc_Overload_Callback_(void * ExprPartHandle);