GetDataTypeMethod
Example 1: Displaying the data type name and size of a variable
Dim MyVariable = uc.DefineVariable("MyVariable")
Console.WriteLine("MyVariable type: " + MyVariable.GetDataType().Name())
Console.WriteLine("MyVariable size: " + MyVariable.GetDataType().ByteSize())
var MyVariable = uc.DefineVariable("MyVariable");
Console.WriteLine("MyVariable type: " + MyVariable.GetDataType().Name());
Console.WriteLine("MyVariable size: " + MyVariable.GetDataType().ByteSize());
WriteLn('MyVariable type: ' + MyVariable.GetDataType().Name());
WriteLn('MyVariable size: ' + MyVariable.GetDataType().ByteSize());
auto MyVariable = uc.DefineVariable("MyVariable");
cout << "MyVariable type: " << MyVariable.GetDataType().Name() << endl;
cout << "MyVariable size: " << MyVariable.GetDataType().ByteSize() << endl;
auto MyVariable = uc.DefineVariable("MyVariable");
Console::WriteLine("MyVariable type: " + MyVariable.GetDataType().Name());
Console::WriteLine("MyVariable size: " + MyVariable.GetDataType().ByteSize());
Example 2: returning data type names for the different definitions of the "+" operator
Dim PlusOperator = uc.GetItemOf("+")
while PlusOperator.ItemHandle <> 0
Console.WriteLine("Def: " + PlusOperator.Text() + " Type: " + PlusOperator.GetDataType().Name())
PlusOperator = PlusOperator.NextOverload()
End while
var PlusOperator = uc.GetItemOf("+");
while (PlusOperator.ItemHandle != null) {
Console.WriteLine("Def: " + PlusOperator.Text() + " Type: " + PlusOperator.GetDataType().Name());
PlusOperator = PlusOperator.NextOverload();
}
while PlusOperator.ItemHandle <> 0 do
begin
WriteLn('Def: ' + PlusOperator.Text() + ' Type: ' + PlusOperator.GetDataType().Name());
PlusOperator = PlusOperator.NextOverload();
End;
auto PlusOperator = uc.GetItemOf("+");
while (PlusOperator.ItemHandle != NULL) {
cout << "Def: " << PlusOperator.Text() << " Type: " << PlusOperator.GetDataType().Name() << endl;
PlusOperator = PlusOperator.NextOverload();
}
auto PlusOperator = uc.GetItemOf("+");
while (PlusOperator.ItemHandle != 0) {
Console::WriteLine("Def: " + PlusOperator.Text() + " Type: " + PlusOperator.GetDataType().Name());
PlusOperator = PlusOperator.NextOverload();
}
Example 3: 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))");
}
Example 4: 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 5: Determining properties of an expression part
Sub OpItemTestCB(ByVal ExprPartPtr As IntPtr)
Dim ExprPart As New uCalc.Callback(ExprPartPtr)
Console.WriteLine("Name: " + ExprPart.OpItem().Name())
Console.WriteLine("Data type: " + ExprPart.OpItem().GetDataType().Name())
Console.WriteLine("Param count: " + ExprPart.OpItem().ElementCount())
Console.WriteLine("Is operator? " + ExprPart.OpItem().IsProperty(ItemIsEnum.Operator_))
End Sub
Sub HandleTest()
uc.DefineFunction("AAA() As Double", uc.PinAddr(AddressOf OpItemTestCB))
uc.DefineFunction("BBB(x, y, z) As String", uc.PinAddr(AddressOf OpItemTestCB))
uc.DefineOperator("{x} CCC {y} As Int32", 0, GroupingEnum.GroupLeftToRight, uc.PinAddr(AddressOf OpItemTestCB)):
uc.EvalStr("AAA()")
uc.EvalStr("BBB(9, 8, 7)")
uc.EvalStr("5 CCC 4")
End Sub
static void OpItemTestCB(IntPtr ExprPartPtr) {
var ExprPart = New uCalc.Callback(ExprPartPtr);
Console.WriteLine("Name: " + ExprPart.OpItem().Name());
Console.WriteLine("Data type: " + ExprPart.OpItem().GetDataType().Name());
Console.WriteLine("Param count: " + ExprPart.OpItem().ElementCount());
Console.WriteLine("Is operator? " + ExprPart.OpItem().IsProperty(ItemIsEnum.Operator));
}
static void HandleTest() {
uc.DefineFunction("AAA() As Double", uc.PinAddr(OpItemTestCB));
uc.DefineFunction("BBB(x, y, z) As String", uc.PinAddr(OpItemTestCB));
uc.DefineOperator("{x} CCC {y} As Int32", 0, GroupingEnum.GroupLeftToRight, uc.PinAddr(OpItemTestCB));
uc.EvalStr("AAA()");
uc.EvalStr("BBB(9, 8, 7)");
uc.EvalStr("5 CCC 4");
}
procedure OpItemTestCB(ExprPartPtr: System.Pointer);
begin
WriteLn('Name: ' + ExprPart.OpItem().Name());
WriteLn('Data type: ' + ExprPart.OpItem().GetDataType().Name());
WriteLn('Param count: ' + ExprPart.OpItem().ElementCount());
WriteLn('Is operator? ' + ExprPart.OpItem().IsProperty(ItemIsEnum.Operator_));
End;
procedure HandleTest();
begin
uc.DefineFunction('AAA() As Double', OpItemTestCB);
uc.DefineFunction('BBB(x, y, z) As String', OpItemTestCB);
uc.DefineOperator('{x} CCC {y} As Int32', 0, GroupingEnum.GroupLeftToRight, OpItemTestCB);
uc.EvalStr('AAA()');
uc.EvalStr('BBB(9, 8, 7)');
uc.EvalStr('5 CCC 4');
End;
void _stdcall OpItemTestCB(uCalcPtr ExprPartPtr) {
auto ExprPart = uCalc::Callback(ExprPartPtr);
cout << "Name: " << ExprPart.OpItem().Name() << endl;
cout << "Data type: " << ExprPart.OpItem().GetDataType().Name() << endl;
cout << "Param count: " << ExprPart.OpItem().ElementCount() << endl;
cout << "Is operator? " << ExprPart.OpItem().IsProperty(ItemIsEnum::Operator) << endl;
}
void HandleTest() {
uc.DefineFunction("AAA() As Double", OpItemTestCB);
uc.DefineFunction("BBB(x, y, z) As String", OpItemTestCB);
uc.DefineOperator("{x} CCC {y} As Int32", 0, GroupingEnum::GroupLeftToRight, OpItemTestCB);
uc.EvalStr("AAA()");
uc.EvalStr("BBB(9, 8, 7)");
uc.EvalStr("5 CCC 4");
}
static void OpItemTestCB(uCalcPtr ExprPartPtr) {
auto ExprPart = uCalc::Callback(ExprPartPtr);
Console::WriteLine("Name: " + ExprPart.OpItem().Name());
Console::WriteLine("Data type: " + ExprPart.OpItem().GetDataType().Name());
Console::WriteLine("Param count: " + ExprPart.OpItem().ElementCount());
Console::WriteLine("Is operator? " + ExprPart.OpItem().IsProperty(ItemIsEnum::Operator));
}
static void HandleTest() {
uc.DefineFunction("AAA() As Double", ucPinAddr(OpItemTestCB));
uc.DefineFunction("BBB(x, y, z) As String", ucPinAddr(OpItemTestCB));
uc.DefineOperator("{x} CCC {y} As Int32", 0, GroupingEnum::GroupLeftToRight, ucPinAddr(OpItemTestCB));
uc.EvalStr("AAA()");
uc.EvalStr("BBB(9, 8, 7)");
uc.EvalStr("5 CCC 4");
}
Example 6: Determining properties of an expression part
Sub OpItemTestCB(ByVal ExprPartPtr As IntPtr)
Dim ExprPart As New uCalc.Callback(ExprPartPtr)
Console.WriteLine("Name: " + ExprPart.OpItem().Name())
Console.WriteLine("Data type: " + ExprPart.OpItem().GetDataType().Name())
Console.WriteLine("Param count: " + ExprPart.OpItem().ElementCount())
Console.WriteLine("Is operator? " + ExprPart.OpItem().IsProperty(ItemIsEnum.Operator_))
End Sub
Sub HandleTest()
uc.DefineFunction("AAA() As Double", uc.PinAddr(AddressOf OpItemTestCB))
uc.DefineFunction("BBB(x, y, z) As String", uc.PinAddr(AddressOf OpItemTestCB))
uc.DefineOperator("{x} CCC {y} As Int32", 0, GroupingEnum.GroupLeftToRight, uc.PinAddr(AddressOf OpItemTestCB)):
uc.EvalStr("AAA()")
uc.EvalStr("BBB(9, 8, 7)")
uc.EvalStr("5 CCC 4")
End Sub
static void OpItemTestCB(IntPtr ExprPartPtr) {
var ExprPart = New uCalc.Callback(ExprPartPtr);
Console.WriteLine("Name: " + ExprPart.OpItem().Name());
Console.WriteLine("Data type: " + ExprPart.OpItem().GetDataType().Name());
Console.WriteLine("Param count: " + ExprPart.OpItem().ElementCount());
Console.WriteLine("Is operator? " + ExprPart.OpItem().IsProperty(ItemIsEnum.Operator));
}
static void HandleTest() {
uc.DefineFunction("AAA() As Double", uc.PinAddr(OpItemTestCB));
uc.DefineFunction("BBB(x, y, z) As String", uc.PinAddr(OpItemTestCB));
uc.DefineOperator("{x} CCC {y} As Int32", 0, GroupingEnum.GroupLeftToRight, uc.PinAddr(OpItemTestCB));
uc.EvalStr("AAA()");
uc.EvalStr("BBB(9, 8, 7)");
uc.EvalStr("5 CCC 4");
}
procedure OpItemTestCB(ExprPartPtr: System.Pointer);
begin
WriteLn('Name: ' + ExprPart.OpItem().Name());
WriteLn('Data type: ' + ExprPart.OpItem().GetDataType().Name());
WriteLn('Param count: ' + ExprPart.OpItem().ElementCount());
WriteLn('Is operator? ' + ExprPart.OpItem().IsProperty(ItemIsEnum.Operator_));
End;
procedure HandleTest();
begin
uc.DefineFunction('AAA() As Double', OpItemTestCB);
uc.DefineFunction('BBB(x, y, z) As String', OpItemTestCB);
uc.DefineOperator('{x} CCC {y} As Int32', 0, GroupingEnum.GroupLeftToRight, OpItemTestCB);
uc.EvalStr('AAA()');
uc.EvalStr('BBB(9, 8, 7)');
uc.EvalStr('5 CCC 4');
End;
void _stdcall OpItemTestCB(uCalcPtr ExprPartPtr) {
auto ExprPart = uCalc::Callback(ExprPartPtr);
cout << "Name: " << ExprPart.OpItem().Name() << endl;
cout << "Data type: " << ExprPart.OpItem().GetDataType().Name() << endl;
cout << "Param count: " << ExprPart.OpItem().ElementCount() << endl;
cout << "Is operator? " << ExprPart.OpItem().IsProperty(ItemIsEnum::Operator) << endl;
}
void HandleTest() {
uc.DefineFunction("AAA() As Double", OpItemTestCB);
uc.DefineFunction("BBB(x, y, z) As String", OpItemTestCB);
uc.DefineOperator("{x} CCC {y} As Int32", 0, GroupingEnum::GroupLeftToRight, OpItemTestCB);
uc.EvalStr("AAA()");
uc.EvalStr("BBB(9, 8, 7)");
uc.EvalStr("5 CCC 4");
}
static void OpItemTestCB(uCalcPtr ExprPartPtr) {
auto ExprPart = uCalc::Callback(ExprPartPtr);
Console::WriteLine("Name: " + ExprPart.OpItem().Name());
Console::WriteLine("Data type: " + ExprPart.OpItem().GetDataType().Name());
Console::WriteLine("Param count: " + ExprPart.OpItem().ElementCount());
Console::WriteLine("Is operator? " + ExprPart.OpItem().IsProperty(ItemIsEnum::Operator));
}
static void HandleTest() {
uc.DefineFunction("AAA() As Double", ucPinAddr(OpItemTestCB));
uc.DefineFunction("BBB(x, y, z) As String", ucPinAddr(OpItemTestCB));
uc.DefineOperator("{x} CCC {y} As Int32", 0, GroupingEnum::GroupLeftToRight, ucPinAddr(OpItemTestCB));
uc.EvalStr("AAA()");
uc.EvalStr("BBB(9, 8, 7)");
uc.EvalStr("5 CCC 4");
}
DLL import code
<DllImport(uCalcDLL, CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Cdecl, EntryPoint:="GetDataType")> _
Private Function GetDataType__(ByVal ItemHandle As IntPtr) As IntPtr
End Function
[DllImport(uCalcDLL, CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl, EntryPoint="GetDataType")]
protected static extern IntPtr GetDataType_(IntPtr ItemHandle);
{DLLImport}function GetDataType__(ItemHandle: System.Pointer): System.Pointer; cdecl; external uCalcDLL name 'GetDataType';
typedef uCalcPtr (* __GetDataType)(void *ItemHandle);
[DllImport(uCalcLib, CharSet=CharSet::Ansi, CallingConvention=CallingConvention::Cdecl, EntryPoint = "GetDataType")]
static uCalcPtr GetDataType_(void * ItemHandle);