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:
Explains the mechanism for bridging the uCalc engine with native host code (C#, C++, VB.NET) via callback functions, including calling conventions and argument handling.
Callbacks are the primary mechanism for creating a bridge between the dynamic uCalc scripting environment and your high-performance, native host application code (C#, C++, VB.NET). A callback allows an expression to call a function in your compiled code, pass it arguments, and receive a value back.
This is essential for:
Callback ObjectWhen you define a function with a callback using DefineFunction or DefineOperator, your native function doesn't receive arguments directly. Instead, it receives a single, special object: the Callback object (often referred to as cb in examples). This object is the sole interface for communicating with the engine.
Inside your callback, you use the cb object to:
The Callback object provides a family of type-safe methods for retrieving arguments.
double.string.⚠️ Important: Argument indexing is 1-based, not 0-based. The first argument is at index 1, the second at index 2, and so on.
You do not use your language's standard return keyword to send a value back to uCalc. You must use the Return... methods on the Callback object.
double.string.How you declare a callback function in your native code depends on the language and platform.
In .NET, a callback is a delegate. The uCalc library provides a DELEGATE_CALLBACK type. You simply create a method with the correct signature and pass its address.
public void MyCallback(uCalc.Callback cb) { /* ... */ }uc.DefineFunction("f()", MyCallback);For more details, see the C# and VB language topics.
On Windows when compiling for x86 (32-bit), you must use the ucalc_call calling convention, which is an alias for __stdcall.
void ucalc_call MyCallback(uCalc::Callback &cb) { /* ... */ }For Windows x64, or other platforms like Linux and macOS, this calling convention is not necessary and can be omitted.
void MyCallback(uCalc::Callback &cb) { /* ... */ }For more details, see the C++ language topic.