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:
An object passed to native callbacks, providing the interface to get arguments, set return values, and interact with the uCalc engine.
The uCalc.Callback class is the essential interface for communication between the uCalc engine and a native callback function in your host application (C#, C++, etc.). You do not create an instance of this class yourself; instead, a Callback object is automatically passed as the sole argument to any native function you register with DefineFunction or DefineOperator.
In all documentation examples, this object is referred to by the conventional name cb.
Its primary roles are:
These methods are used to get the values passed to your function from the uCalc expression.
| Member | Description |
|---|---|
Arg | Retrieves a numeric argument as a double-precision float. |
Arg1 | A high-performance shortcut for retrieving the first numeric argument. |
Arg2 | A high-performance shortcut for retrieving the second numeric argument. |
ArgAddr | Retrieves a direct memory pointer to an argument's value, for low-level operations. |
ArgBool | Retrieves a boolean argument, with automatic type conversion. |
ArgCount | Gets the total number of arguments passed to the callback, essential for variadic functions. |
ArgDbl | Retrieves a double-precision argument, functionally identical to Arg. |
ArgExpr | Retrieves an argument as an unevaluated Expression object for lazy evaluation (ByExpr). |
ArgInt16 | Retrieves a 16-bit integer argument. |
ArgInt32 | Retrieves a 32-bit integer argument. |
ArgInt64 | Retrieves a 64-bit integer argument. |
ArgItem | Retrieves the full metadata Item object for an argument, for introspection (ByHandle). |
ArgPtr | Retrieves the value of an argument that is a pointer. |
ArgStr | Retrieves an argument as a string, with automatic type conversion. |
These methods are used to send a result from your callback back to the uCalc engine.
| Member | Description |
|---|---|
Return | Sets the double-precision return value for the callback. |
ReturnBool | Sets the boolean return value. |
ReturnDbl | Sets the double-precision return value, functionally identical to Return. |
ReturnInt16 | Sets the 16-bit integer return value. |
ReturnInt32 | Sets the 32-bit integer return value. |
ReturnInt64 | Sets the 64-bit integer return value. |
ReturnPtr | Sets a pointer as the return value. |
ReturnStr | Sets the string return value. |
These properties provide access to the surrounding execution environment.
| Member | Description |
|---|---|
uCalc | Retrieves the parent uCalc instance that is executing the callback. |
Item | Retrieves the Item object for the function or operator that triggered the callback. |
These members allow you to manage errors from within a callback.
| Member | Description |
|---|---|
Error | Provides access to the ErrorInfo object to raise errors or inspect error state. |
Raise | Triggers a uCalc error with a predefined code or a custom message. |
| Member | Description |
|---|---|
Handle | Retrieves the internal, low-level identifier for the callback context object. |
ID: 12
using uCalcSoftware;
var uc = new uCalc();
static void MyAverage(uCalc.Callback cb) {
double Total = 0;
for (int x = 1; x <= cb.ArgCount(); x++) {
Total = Total + cb.Arg(x);
}
cb.Return(Total / cb.ArgCount());
}
uc.DefineFunction("Average(x ...)", MyAverage);
Console.WriteLine(uc.Eval("Average(10, 3, 7, 4)"));
6 using uCalcSoftware; var uc = new uCalc(); static void MyAverage(uCalc.Callback cb) { double Total = 0; for (int x = 1; x <= cb.ArgCount(); x++) { Total = Total + cb.Arg(x); } cb.Return(Total / cb.ArgCount()); } uc.DefineFunction("Average(x ...)", MyAverage); Console.WriteLine(uc.Eval("Average(10, 3, 7, 4)"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
void ucalc_call MyAverage(uCalcBase::Callback cb) {
double Total = 0;
for (int x = 1; x <= cb.ArgCount(); x++) {
Total = Total + cb.Arg(x);
}
cb.Return(Total / cb.ArgCount());
}
int main() {
uCalc uc;
uc.DefineFunction("Average(x ...)", MyAverage);
cout << uc.Eval("Average(10, 3, 7, 4)") << endl;
}
6 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; void ucalc_call MyAverage(uCalcBase::Callback cb) { double Total = 0; for (int x = 1; x <= cb.ArgCount(); x++) { Total = Total + cb.Arg(x); } cb.Return(Total / cb.ArgCount()); } int main() { uCalc uc; uc.DefineFunction("Average(x ...)", MyAverage); cout << uc.Eval("Average(10, 3, 7, 4)") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub MyAverage(ByVal cb As uCalc.Callback)
Dim Total As Double = 0
For x As Integer = 1 To cb.ArgCount()
Total = Total + cb.Arg(x)
Next
cb.Return(Total / cb.ArgCount())
End Sub
Public Sub Main()
Dim uc As New uCalc()
uc.DefineFunction("Average(x ...)", AddressOf MyAverage)
Console.WriteLine(uc.Eval("Average(10, 3, 7, 4)"))
End Sub
End Module
6 Imports System Imports uCalcSoftware Public Module Program Public Sub MyAverage(ByVal cb As uCalc.Callback) Dim Total As Double = 0 For x As Integer = 1 To cb.ArgCount() Total = Total + cb.Arg(x) Next cb.Return(Total / cb.ArgCount()) End Sub Public Sub Main() Dim uc As New uCalc() uc.DefineFunction("Average(x ...)", AddressOf MyAverage) Console.WriteLine(uc.Eval("Average(10, 3, 7, 4)")) End Sub End Module