uCalc API Version: 2.1.3-preview.2 Released: 6/16/2026
Warning
uCalc API Preview Release Notice:The documentation describes the intended behavior of the API. The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.
ArgInt32
Method
Product:
Class:
Retrieves a 32-bit integer argument passed to a user-defined callback function.
Syntax
Parameters
Return
int32
The value of the specified argument as a 32-bit integer.
Remarks
The ArgInt32 method retrieves an argument from within a user-defined callback. This method does not perform any type conversion itself; rather, it provides type-safe access to an argument that the uCalc engine has already processed and stored as a 32-bit integer. This is based on the function signature you provide to DefineFunction or DefineOperator.
Argument Indexing
It's crucial to note that the index parameter is 1-based. The first argument passed to your function is retrieved with ArgInt32(1), the second with ArgInt32(2), and so on.
⚙️ Engine-Level Type Coercion
When you define a function with strongly-typed parameters, such as MyFunc(x As Int32), the uCalc evaluation engine takes responsibility for type coercion. If a user's expression provides a different numeric type, like MyFunc(123.8), the engine will automatically convert 123.8 to the Int32 value 123 (by truncating the decimal part) before your callback function is invoked. The ArgInt32(1) call inside your callback then simply reads this pre-converted 32-bit integer value.
This design ensures that by the time your callback code executes, the arguments are already in the expected format, simplifying your logic and preventing runtime type errors.
💡 Comparative Analysis
vs. Native C#/C++: In native languages, you might handle variant types or
objectparameters, requiring manual type checking and casting inside the function body. uCalc's approach is different: the engine enforces the type contract defined in the function signature before execution enters the callback. This moves the responsibility of type safety from the callback implementer to the engine itself, resulting in cleaner, safer code.vs. Generic
Arg(index): A genericArgmethod would return a variant type that requires inspection. The type-specific accessors likeArgInt32align with uCalc's philosophy of strong typing at the script level, allowing you to confidently retrieve an argument in the format you declared.
Examples
How to handle and retrieve various data types (including pointers) within a callback.
using uCalcSoftware;
var uc = new uCalc();
static void MyFunction(uCalc.Callback cb) {
var uc = cb.uCalc;
Console.WriteLine("------ MyFunc ------");
// Retrieve standard 32-bit and 64-bit integer arguments directly
Console.WriteLine(cb.ArgInt32(1));
Console.WriteLine(cb.ArgInt64(2));
// Retrieve the value of a pointer argument by referencing its exact data type.
Console.WriteLine(uc.ItemOf("Int8").DataType.ToString(cb.ArgAddr(3)));
// The Item object correctly identifies the type before conversion
Console.WriteLine(uc.ItemOf("Int").DataType.ToString(cb.ArgPtr(4)));
}
static void MyFunction2(uCalc.Callback cb) {
var uc = cb.uCalc;
Console.WriteLine("------ MyFunc2 ------");
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8).ToString(cb.ArgPtr(1)));
}
static void MyFunction3(uCalc.Callback cb) {
var uc = cb.uCalc;
Console.WriteLine("------ MyFunc3 ------");
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_16).ToString(cb.ArgPtr(1)));
}
uc.DefineVariable("x As Int = 123"); // Int32
uc.DefineVariable("xPtr As Int Ptr = AddressOf(x)");
uc.DefineFunction("MyFunc(a As Int32, b As Int64, c As Byte, d As Int Ptr)", MyFunction);
uc.Eval("MyFunc(x*10, 1+1, 255, xPtr)");
uc.DefineVariable("x2 As Int8 = -123");
uc.DefineVariable("xPtr2 As Int8 Ptr = AddressOf(x2)");
uc.DefineFunction("MyFunc2(d As Int8 Ptr)", MyFunction2);
uc.Eval("MyFunc2(xPtr2)");
uc.DefineVariable("x3 As Int16 = 1234");
uc.DefineVariable("xPtr3 As Int16 Ptr = AddressOf(x3)");
uc.DefineFunction("MyFunc3(d As Int16 Ptr)", MyFunction3);
uc.Eval("MyFunc3(xPtr3)");
------ MyFunc ------
1230
2
-1
123
------ MyFunc2 ------
-123
------ MyFunc3 ------
1234 using uCalcSoftware; var uc = new uCalc(); static void MyFunction(uCalc.Callback cb) { var uc = cb.uCalc; Console.WriteLine("------ MyFunc ------"); // Retrieve standard 32-bit and 64-bit integer arguments directly Console.WriteLine(cb.ArgInt32(1)); Console.WriteLine(cb.ArgInt64(2)); // Retrieve the value of a pointer argument by referencing its exact data type. Console.WriteLine(uc.ItemOf("Int8").DataType.ToString(cb.ArgAddr(3))); // The Item object correctly identifies the type before conversion Console.WriteLine(uc.ItemOf("Int").DataType.ToString(cb.ArgPtr(4))); } static void MyFunction2(uCalc.Callback cb) { var uc = cb.uCalc; Console.WriteLine("------ MyFunc2 ------"); Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8).ToString(cb.ArgPtr(1))); } static void MyFunction3(uCalc.Callback cb) { var uc = cb.uCalc; Console.WriteLine("------ MyFunc3 ------"); Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_16).ToString(cb.ArgPtr(1))); } uc.DefineVariable("x As Int = 123"); // Int32 uc.DefineVariable("xPtr As Int Ptr = AddressOf(x)"); uc.DefineFunction("MyFunc(a As Int32, b As Int64, c As Byte, d As Int Ptr)", MyFunction); uc.Eval("MyFunc(x*10, 1+1, 255, xPtr)"); uc.DefineVariable("x2 As Int8 = -123"); uc.DefineVariable("xPtr2 As Int8 Ptr = AddressOf(x2)"); uc.DefineFunction("MyFunc2(d As Int8 Ptr)", MyFunction2); uc.Eval("MyFunc2(xPtr2)"); uc.DefineVariable("x3 As Int16 = 1234"); uc.DefineVariable("xPtr3 As Int16 Ptr = AddressOf(x3)"); uc.DefineFunction("MyFunc3(d As Int16 Ptr)", MyFunction3); uc.Eval("MyFunc3(xPtr3)");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
void ucalc_call MyFunction(uCalcBase::Callback cb) {
auto uc = cb.uCalc();
cout << "------ MyFunc ------" << endl;
// Retrieve standard 32-bit and 64-bit integer arguments directly
cout << cb.ArgInt32(1) << endl;
cout << cb.ArgInt64(2) << endl;
// Retrieve the value of a pointer argument by referencing its exact data type.
cout << uc.ItemOf("Int8").DataType().ToString(cb.ArgAddr(3)) << endl;
// The Item object correctly identifies the type before conversion
cout << uc.ItemOf("Int").DataType().ToString(cb.ArgPtr(4)) << endl;
}
void ucalc_call MyFunction2(uCalcBase::Callback cb) {
auto uc = cb.uCalc();
cout << "------ MyFunc2 ------" << endl;
cout << uc.DataTypeOf(BuiltInType::Integer_8).ToString(cb.ArgPtr(1)) << endl;
}
void ucalc_call MyFunction3(uCalcBase::Callback cb) {
auto uc = cb.uCalc();
cout << "------ MyFunc3 ------" << endl;
cout << uc.DataTypeOf(BuiltInType::Integer_16).ToString(cb.ArgPtr(1)) << endl;
}
int main() {
uCalc uc;
uc.DefineVariable("x As Int = 123"); // Int32
uc.DefineVariable("xPtr As Int Ptr = AddressOf(x)");
uc.DefineFunction("MyFunc(a As Int32, b As Int64, c As Byte, d As Int Ptr)", MyFunction);
uc.Eval("MyFunc(x*10, 1+1, 255, xPtr)");
uc.DefineVariable("x2 As Int8 = -123");
uc.DefineVariable("xPtr2 As Int8 Ptr = AddressOf(x2)");
uc.DefineFunction("MyFunc2(d As Int8 Ptr)", MyFunction2);
uc.Eval("MyFunc2(xPtr2)");
uc.DefineVariable("x3 As Int16 = 1234");
uc.DefineVariable("xPtr3 As Int16 Ptr = AddressOf(x3)");
uc.DefineFunction("MyFunc3(d As Int16 Ptr)", MyFunction3);
uc.Eval("MyFunc3(xPtr3)");
}
------ MyFunc ------
1230
2
-1
123
------ MyFunc2 ------
-123
------ MyFunc3 ------
1234 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; void ucalc_call MyFunction(uCalcBase::Callback cb) { auto uc = cb.uCalc(); cout << "------ MyFunc ------" << endl; // Retrieve standard 32-bit and 64-bit integer arguments directly cout << cb.ArgInt32(1) << endl; cout << cb.ArgInt64(2) << endl; // Retrieve the value of a pointer argument by referencing its exact data type. cout << uc.ItemOf("Int8").DataType().ToString(cb.ArgAddr(3)) << endl; // The Item object correctly identifies the type before conversion cout << uc.ItemOf("Int").DataType().ToString(cb.ArgPtr(4)) << endl; } void ucalc_call MyFunction2(uCalcBase::Callback cb) { auto uc = cb.uCalc(); cout << "------ MyFunc2 ------" << endl; cout << uc.DataTypeOf(BuiltInType::Integer_8).ToString(cb.ArgPtr(1)) << endl; } void ucalc_call MyFunction3(uCalcBase::Callback cb) { auto uc = cb.uCalc(); cout << "------ MyFunc3 ------" << endl; cout << uc.DataTypeOf(BuiltInType::Integer_16).ToString(cb.ArgPtr(1)) << endl; } int main() { uCalc uc; uc.DefineVariable("x As Int = 123"); // Int32 uc.DefineVariable("xPtr As Int Ptr = AddressOf(x)"); uc.DefineFunction("MyFunc(a As Int32, b As Int64, c As Byte, d As Int Ptr)", MyFunction); uc.Eval("MyFunc(x*10, 1+1, 255, xPtr)"); uc.DefineVariable("x2 As Int8 = -123"); uc.DefineVariable("xPtr2 As Int8 Ptr = AddressOf(x2)"); uc.DefineFunction("MyFunc2(d As Int8 Ptr)", MyFunction2); uc.Eval("MyFunc2(xPtr2)"); uc.DefineVariable("x3 As Int16 = 1234"); uc.DefineVariable("xPtr3 As Int16 Ptr = AddressOf(x3)"); uc.DefineFunction("MyFunc3(d As Int16 Ptr)", MyFunction3); uc.Eval("MyFunc3(xPtr3)"); }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub MyFunction(ByVal cb As uCalc.Callback)
Dim uc = cb.uCalc
Console.WriteLine("------ MyFunc ------")
'// Retrieve standard 32-bit and 64-bit integer arguments directly
Console.WriteLine(cb.ArgInt32(1))
Console.WriteLine(cb.ArgInt64(2))
'// Retrieve the value of a pointer argument by referencing its exact data type.
Console.WriteLine(uc.ItemOf("Int8").DataType.ToString(cb.ArgAddr(3)))
'// The Item object correctly identifies the type before conversion
Console.WriteLine(uc.ItemOf("Int").DataType.ToString(cb.ArgPtr(4)))
End Sub
Public Sub MyFunction2(ByVal cb As uCalc.Callback)
Dim uc = cb.uCalc
Console.WriteLine("------ MyFunc2 ------")
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8).ToString(cb.ArgPtr(1)))
End Sub
Public Sub MyFunction3(ByVal cb As uCalc.Callback)
Dim uc = cb.uCalc
Console.WriteLine("------ MyFunc3 ------")
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_16).ToString(cb.ArgPtr(1)))
End Sub
Public Sub Main()
Dim uc As New uCalc()
uc.DefineVariable("x As Int = 123") '// Int32
uc.DefineVariable("xPtr As Int Ptr = AddressOf(x)")
uc.DefineFunction("MyFunc(a As Int32, b As Int64, c As Byte, d As Int Ptr)", AddressOf MyFunction)
uc.Eval("MyFunc(x*10, 1+1, 255, xPtr)")
uc.DefineVariable("x2 As Int8 = -123")
uc.DefineVariable("xPtr2 As Int8 Ptr = AddressOf(x2)")
uc.DefineFunction("MyFunc2(d As Int8 Ptr)", AddressOf MyFunction2)
uc.Eval("MyFunc2(xPtr2)")
uc.DefineVariable("x3 As Int16 = 1234")
uc.DefineVariable("xPtr3 As Int16 Ptr = AddressOf(x3)")
uc.DefineFunction("MyFunc3(d As Int16 Ptr)", AddressOf MyFunction3)
uc.Eval("MyFunc3(xPtr3)")
End Sub
End Module
------ MyFunc ------
1230
2
-1
123
------ MyFunc2 ------
-123
------ MyFunc3 ------
1234 Imports System Imports uCalcSoftware Public Module Program Public Sub MyFunction(ByVal cb As uCalc.Callback) Dim uc = cb.uCalc Console.WriteLine("------ MyFunc ------") '// Retrieve standard 32-bit and 64-bit integer arguments directly Console.WriteLine(cb.ArgInt32(1)) Console.WriteLine(cb.ArgInt64(2)) '// Retrieve the value of a pointer argument by referencing its exact data type. Console.WriteLine(uc.ItemOf("Int8").DataType.ToString(cb.ArgAddr(3))) '// The Item object correctly identifies the type before conversion Console.WriteLine(uc.ItemOf("Int").DataType.ToString(cb.ArgPtr(4))) End Sub Public Sub MyFunction2(ByVal cb As uCalc.Callback) Dim uc = cb.uCalc Console.WriteLine("------ MyFunc2 ------") Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8).ToString(cb.ArgPtr(1))) End Sub Public Sub MyFunction3(ByVal cb As uCalc.Callback) Dim uc = cb.uCalc Console.WriteLine("------ MyFunc3 ------") Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_16).ToString(cb.ArgPtr(1))) End Sub Public Sub Main() Dim uc As New uCalc() uc.DefineVariable("x As Int = 123") '// Int32 uc.DefineVariable("xPtr As Int Ptr = AddressOf(x)") uc.DefineFunction("MyFunc(a As Int32, b As Int64, c As Byte, d As Int Ptr)", AddressOf MyFunction) uc.Eval("MyFunc(x*10, 1+1, 255, xPtr)") uc.DefineVariable("x2 As Int8 = -123") uc.DefineVariable("xPtr2 As Int8 Ptr = AddressOf(x2)") uc.DefineFunction("MyFunc2(d As Int8 Ptr)", AddressOf MyFunction2) uc.Eval("MyFunc2(xPtr2)") uc.DefineVariable("x3 As Int16 = 1234") uc.DefineVariable("xPtr3 As Int16 Ptr = AddressOf(x3)") uc.DefineFunction("MyFunc3(d As Int16 Ptr)", AddressOf MyFunction3) uc.Eval("MyFunc3(xPtr3)") End Sub End Module
Return and other type-specific versions of Return
using uCalcSoftware;
var uc = new uCalc();
static void BooleanAnd(uCalc.Callback cb) {
cb.ReturnBool(cb.ArgBool(1) && cb.ArgBool(2));
}
static void AddInt16(uCalc.Callback cb) {
//C# promots Int16 to int for arithmetic hence (Int16) to convert it back
cb.ReturnInt16((Int16)(cb.ArgInt16(1) + cb.ArgInt16(2)));
}
static void AddInt32(uCalc.Callback cb) {
cb.ReturnInt32(cb.ArgInt32(1) + cb.ArgInt32(2));
}
static void AddInt64(uCalc.Callback cb) {
cb.ReturnInt64(cb.ArgInt64(1) + cb.ArgInt64(2));
}
uc.DefineFunction("BooleanAnd(x As Bool, y As Bool) As Bool", BooleanAnd);
uc.DefineFunction("AddInt16(x As Int16, y As Int16) As Int16", AddInt16);
uc.DefineFunction("AddInt32(x As Int32, y As Int32) As Int32", AddInt32);
uc.DefineFunction("AddInt64(x As Int64, y As Int64) As Int64", AddInt64);
Console.WriteLine(uc.EvalStr("BooleanAnd(true, false)"));
Console.WriteLine(uc.EvalStr("AddInt16(5.2, 4.1)"));
Console.WriteLine(uc.EvalStr("AddInt32(2, 3)"));
Console.WriteLine(uc.EvalStr("AddInt64(10, 20)"));
false
9
5
30 using uCalcSoftware; var uc = new uCalc(); static void BooleanAnd(uCalc.Callback cb) { cb.ReturnBool(cb.ArgBool(1) && cb.ArgBool(2)); } static void AddInt16(uCalc.Callback cb) { //C# promots Int16 to int for arithmetic hence (Int16) to convert it back cb.ReturnInt16((Int16)(cb.ArgInt16(1) + cb.ArgInt16(2))); } static void AddInt32(uCalc.Callback cb) { cb.ReturnInt32(cb.ArgInt32(1) + cb.ArgInt32(2)); } static void AddInt64(uCalc.Callback cb) { cb.ReturnInt64(cb.ArgInt64(1) + cb.ArgInt64(2)); } uc.DefineFunction("BooleanAnd(x As Bool, y As Bool) As Bool", BooleanAnd); uc.DefineFunction("AddInt16(x As Int16, y As Int16) As Int16", AddInt16); uc.DefineFunction("AddInt32(x As Int32, y As Int32) As Int32", AddInt32); uc.DefineFunction("AddInt64(x As Int64, y As Int64) As Int64", AddInt64); Console.WriteLine(uc.EvalStr("BooleanAnd(true, false)")); Console.WriteLine(uc.EvalStr("AddInt16(5.2, 4.1)")); Console.WriteLine(uc.EvalStr("AddInt32(2, 3)")); Console.WriteLine(uc.EvalStr("AddInt64(10, 20)"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
void ucalc_call BooleanAnd(uCalcBase::Callback cb) {
cb.ReturnBool(cb.ArgBool(1) && cb.ArgBool(2));
}
void ucalc_call AddInt16(uCalcBase::Callback cb) {
cb.ReturnInt16(cb.ArgInt16(1) + cb.ArgInt16(2));
}
void ucalc_call AddInt32(uCalcBase::Callback cb) {
cb.ReturnInt32(cb.ArgInt32(1) + cb.ArgInt32(2));
}
void ucalc_call AddInt64(uCalcBase::Callback cb) {
cb.ReturnInt64(cb.ArgInt64(1) + cb.ArgInt64(2));
}
int main() {
uCalc uc;
uc.DefineFunction("BooleanAnd(x As Bool, y As Bool) As Bool", BooleanAnd);
uc.DefineFunction("AddInt16(x As Int16, y As Int16) As Int16", AddInt16);
uc.DefineFunction("AddInt32(x As Int32, y As Int32) As Int32", AddInt32);
uc.DefineFunction("AddInt64(x As Int64, y As Int64) As Int64", AddInt64);
cout << uc.EvalStr("BooleanAnd(true, false)") << endl;
cout << uc.EvalStr("AddInt16(5.2, 4.1)") << endl;
cout << uc.EvalStr("AddInt32(2, 3)") << endl;
cout << uc.EvalStr("AddInt64(10, 20)") << endl;
}
false
9
5
30 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; void ucalc_call BooleanAnd(uCalcBase::Callback cb) { cb.ReturnBool(cb.ArgBool(1) && cb.ArgBool(2)); } void ucalc_call AddInt16(uCalcBase::Callback cb) { cb.ReturnInt16(cb.ArgInt16(1) + cb.ArgInt16(2)); } void ucalc_call AddInt32(uCalcBase::Callback cb) { cb.ReturnInt32(cb.ArgInt32(1) + cb.ArgInt32(2)); } void ucalc_call AddInt64(uCalcBase::Callback cb) { cb.ReturnInt64(cb.ArgInt64(1) + cb.ArgInt64(2)); } int main() { uCalc uc; uc.DefineFunction("BooleanAnd(x As Bool, y As Bool) As Bool", BooleanAnd); uc.DefineFunction("AddInt16(x As Int16, y As Int16) As Int16", AddInt16); uc.DefineFunction("AddInt32(x As Int32, y As Int32) As Int32", AddInt32); uc.DefineFunction("AddInt64(x As Int64, y As Int64) As Int64", AddInt64); cout << uc.EvalStr("BooleanAnd(true, false)") << endl; cout << uc.EvalStr("AddInt16(5.2, 4.1)") << endl; cout << uc.EvalStr("AddInt32(2, 3)") << endl; cout << uc.EvalStr("AddInt64(10, 20)") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub BooleanAnd(ByVal cb As uCalc.Callback)
cb.ReturnBool(cb.ArgBool(1) And cb.ArgBool(2))
End Sub
Public Sub AddInt16(ByVal cb As uCalc.Callback)
cb.ReturnInt16(cb.ArgInt16(1) + cb.ArgInt16(2))
End Sub
Public Sub AddInt32(ByVal cb As uCalc.Callback)
cb.ReturnInt32(cb.ArgInt32(1) + cb.ArgInt32(2))
End Sub
Public Sub AddInt64(ByVal cb As uCalc.Callback)
cb.ReturnInt64(cb.ArgInt64(1) + cb.ArgInt64(2))
End Sub
Public Sub Main()
Dim uc As New uCalc()
uc.DefineFunction("BooleanAnd(x As Bool, y As Bool) As Bool", AddressOf BooleanAnd)
uc.DefineFunction("AddInt16(x As Int16, y As Int16) As Int16", AddressOf AddInt16)
uc.DefineFunction("AddInt32(x As Int32, y As Int32) As Int32", AddressOf AddInt32)
uc.DefineFunction("AddInt64(x As Int64, y As Int64) As Int64", AddressOf AddInt64)
Console.WriteLine(uc.EvalStr("BooleanAnd(true, false)"))
Console.WriteLine(uc.EvalStr("AddInt16(5.2, 4.1)"))
Console.WriteLine(uc.EvalStr("AddInt32(2, 3)"))
Console.WriteLine(uc.EvalStr("AddInt64(10, 20)"))
End Sub
End Module
false
9
5
30 Imports System Imports uCalcSoftware Public Module Program Public Sub BooleanAnd(ByVal cb As uCalc.Callback) cb.ReturnBool(cb.ArgBool(1) And cb.ArgBool(2)) End Sub Public Sub AddInt16(ByVal cb As uCalc.Callback) cb.ReturnInt16(cb.ArgInt16(1) + cb.ArgInt16(2)) End Sub Public Sub AddInt32(ByVal cb As uCalc.Callback) cb.ReturnInt32(cb.ArgInt32(1) + cb.ArgInt32(2)) End Sub Public Sub AddInt64(ByVal cb As uCalc.Callback) cb.ReturnInt64(cb.ArgInt64(1) + cb.ArgInt64(2)) End Sub Public Sub Main() Dim uc As New uCalc() uc.DefineFunction("BooleanAnd(x As Bool, y As Bool) As Bool", AddressOf BooleanAnd) uc.DefineFunction("AddInt16(x As Int16, y As Int16) As Int16", AddressOf AddInt16) uc.DefineFunction("AddInt32(x As Int32, y As Int32) As Int32", AddressOf AddInt32) uc.DefineFunction("AddInt64(x As Int64, y As Int64) As Int64", AddressOf AddInt64) Console.WriteLine(uc.EvalStr("BooleanAnd(true, false)")) Console.WriteLine(uc.EvalStr("AddInt16(5.2, 4.1)")) Console.WriteLine(uc.EvalStr("AddInt32(2, 3)")) Console.WriteLine(uc.EvalStr("AddInt64(10, 20)")) End Sub End Module