uCalc API Version: 5.7.0-preview.1 Released: 7/30/2026
Warning
uCalc API Preview Release Notice:This preview documentation describes the intended behavior of the API. It is not fully accurate or complete.The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.Use of the preview version in your production code is not recommended.
Product:
Class:
Retrieves a direct memory pointer to the value of an argument passed to a callback function.
Returns a raw memory pointer (void* or IntPtr) to the argument's value. This pointer must be cast to the correct type before use.
The ArgAddr method is a low-level tool for advanced callback scenarios, providing direct memory access to an argument's value. It is typically used when a strongly-typed accessor (like ArgInt32 or ArgStr) is not available for a specific data type, or when you need to interact with the argument's underlying memory.
Generic Value Retrieval: When working with custom or non-standard data types, ArgAddr provides a universal way to get a pointer to the value. You can then use the argument's DataType object to safely read or convert this value.
Modifying ByRef Arguments: If a function parameter is defined with the ByRef modifier, ArgAddr gives you the memory address of the original variable. This allows the callback to modify the variable's value in the caller's scope, a key feature for creating functions with side effects.
ArgAddr vs. ArgPtrIt is crucial to understand the distinction between these two methods:
ArgAddr(n): Returns the memory address of the nth argument itself. This is the location on the call stack or in a register where the argument's value is stored.ArgPtr(n): Returns the value of the nth argument, assuming that value is a pointer. It reads the data from the argument's location and interprets it as a memory address.See the internal test example for a practical demonstration of this difference.
In native C/C++, accessing function arguments might involve variadic argument lists (va_list) or direct stack manipulation, which can be unsafe and complex. uCalc's Callback model abstracts this away.
ArgAddr provides a consistent, safe, and platform-agnostic way to get a memory pointer to an argument within the sandboxed uCalc environment. It simplifies interoperability between the uCalc engine and the host application's data.Note: The argument index is 1-based. The first argument is at index 1, not 0.
ID: 16
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