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.
Item = [Item]
Property
Product:
Class:
Retrieves the Item object for the function or operator that triggered the callback.
Remarks
🕵️♀️ Introspecting the Caller
The Item() method, available on the cb (callback) object, provides a powerful introspection capability. It returns the complete Item object that represents the function or operator whose execution triggered the current callback. This allows your native code to access the full definition and metadata of the symbol that is currently being evaluated.
🎯 Primary Use Case: Shared Callbacks
Its most critical use case is for disambiguation when multiple functions or operators are mapped to a single, generic callback function. Inside the callback, cb.Item() is the primary mechanism to determine which specific symbol was invoked, enabling you to implement different logic based on the caller.
By inspecting the returned Item object, you can query its properties:
- Name: Item.Name()
- Data Type: Item.DataType()
- Parameter Count: Item.Count()
- Symbol Type: Item.IsProperty(ItemIs::Function)
- Original Definition: Item.Text()
- User-Supplied Description: Item.Description()
💡 Comparative Analysis
- vs. Reflection (C#
MethodBase.GetCurrentMethod()/ C++__func__): Standard language features for introspection typically return only the name of the current function as a string. uCalc'scb.Item()is significantly more powerful. It returns a rich, structured object that provides deep access to the symbol's properties as defined within the uCalc engine. This allows for more intelligent, context-aware logic inside your callbacks than is possible with simple name-based reflection.
Examples
Succinct: Disambiguates which function or operator triggered a shared callback.
using uCalcSoftware;
var uc = new uCalc();
static void SharedCallback(uCalc.Callback cb) {
Console.WriteLine($"Callback triggered by: {cb.Item.Name}");
}
// Define two different symbols that use the same callback
uc.DefineFunction("FuncA(x, y)", SharedCallback);
uc.DefineOperator("{x} OpB {y}", 100, Associativity.LeftToRight, SharedCallback);
// Call both symbols
uc.EvalStr("FuncA(1, 2)");
uc.EvalStr("1 OpB 2");
Callback triggered by: funca
Callback triggered by: opb using uCalcSoftware; var uc = new uCalc(); static void SharedCallback(uCalc.Callback cb) { Console.WriteLine($"Callback triggered by: {cb.Item.Name}"); } // Define two different symbols that use the same callback uc.DefineFunction("FuncA(x, y)", SharedCallback); uc.DefineOperator("{x} OpB {y}", 100, Associativity.LeftToRight, SharedCallback); // Call both symbols uc.EvalStr("FuncA(1, 2)"); uc.EvalStr("1 OpB 2");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
void ucalc_call SharedCallback(uCalcBase::Callback cb) {
cout << "Callback triggered by: " << cb.Item().Name() << endl;
}
int main() {
uCalc uc;
// Define two different symbols that use the same callback
uc.DefineFunction("FuncA(x, y)", SharedCallback);
uc.DefineOperator("{x} OpB {y}", 100, Associativity::LeftToRight, SharedCallback);
// Call both symbols
uc.EvalStr("FuncA(1, 2)");
uc.EvalStr("1 OpB 2");
}
Callback triggered by: funca
Callback triggered by: opb #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; void ucalc_call SharedCallback(uCalcBase::Callback cb) { cout << "Callback triggered by: " << cb.Item().Name() << endl; } int main() { uCalc uc; // Define two different symbols that use the same callback uc.DefineFunction("FuncA(x, y)", SharedCallback); uc.DefineOperator("{x} OpB {y}", 100, Associativity::LeftToRight, SharedCallback); // Call both symbols uc.EvalStr("FuncA(1, 2)"); uc.EvalStr("1 OpB 2"); }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub SharedCallback(ByVal cb As uCalc.Callback)
Console.WriteLine($"Callback triggered by: {cb.Item.Name}")
End Sub
Public Sub Main()
Dim uc As New uCalc()
'// Define two different symbols that use the same callback
uc.DefineFunction("FuncA(x, y)", AddressOf SharedCallback)
uc.DefineOperator("{x} OpB {y}", 100, Associativity.LeftToRight, AddressOf SharedCallback)
'// Call both symbols
uc.EvalStr("FuncA(1, 2)")
uc.EvalStr("1 OpB 2")
End Sub
End Module
Callback triggered by: funca
Callback triggered by: opb Imports System Imports uCalcSoftware Public Module Program Public Sub SharedCallback(ByVal cb As uCalc.Callback) Console.WriteLine($"Callback triggered by: {cb.Item.Name}") End Sub Public Sub Main() Dim uc As New uCalc() '// Define two different symbols that use the same callback uc.DefineFunction("FuncA(x, y)", AddressOf SharedCallback) uc.DefineOperator("{x} OpB {y}", 100, Associativity.LeftToRight, AddressOf SharedCallback) '// Call both symbols uc.EvalStr("FuncA(1, 2)") uc.EvalStr("1 OpB 2") End Sub End Module
Determining properties of an expression part
using uCalcSoftware;
var uc = new uCalc();
static void ItemCallback(uCalc.Callback cb) {
Console.WriteLine($"Name: {cb.Item.Name}");
Console.WriteLine($"Data type: {cb.Item.DataType.Name}");
Console.WriteLine($"Param count: {cb.Item.Count}");
Console.Write("Procedure type: ");
if (cb.Item.IsProperty(ItemIs.Operator)) {
Console.WriteLine("Operator");
} else if (cb.Item.IsProperty(ItemIs.Function)) {
Console.WriteLine("Function");
}
Console.WriteLine(cb.Item.Text);
Console.WriteLine(cb.Item.Description);
Console.WriteLine("---");
}
uc.DefineFunction("AAA() As Double", ItemCallback).Description = "Does this and that";
uc.DefineFunction("BBB(x, y, z) As String", ItemCallback).Description = "Does something else";
uc.DefineOperator("{x} CCC {y} As Int32", 0, Associativity.LeftToRight, ItemCallback);
uc.EvalStr("AAA()");
uc.EvalStr("BBB(9, 8, 7)");
uc.EvalStr("5 CCC 4");
Name: aaa
Data type: double
Param count: 0
Procedure type: Function
Function: AAA() As Double
Does this and that
---
Name: bbb
Data type: string
Param count: 3
Procedure type: Function
Function: BBB(x, y, z) As String
Does something else
---
Name: ccc
Data type: int
Param count: 2
Procedure type: Operator
Operator: {x} CCC {y} As Int32
--- using uCalcSoftware; var uc = new uCalc(); static void ItemCallback(uCalc.Callback cb) { Console.WriteLine($"Name: {cb.Item.Name}"); Console.WriteLine($"Data type: {cb.Item.DataType.Name}"); Console.WriteLine($"Param count: {cb.Item.Count}"); Console.Write("Procedure type: "); if (cb.Item.IsProperty(ItemIs.Operator)) { Console.WriteLine("Operator"); } else if (cb.Item.IsProperty(ItemIs.Function)) { Console.WriteLine("Function"); } Console.WriteLine(cb.Item.Text); Console.WriteLine(cb.Item.Description); Console.WriteLine("---"); } uc.DefineFunction("AAA() As Double", ItemCallback).Description = "Does this and that"; uc.DefineFunction("BBB(x, y, z) As String", ItemCallback).Description = "Does something else"; uc.DefineOperator("{x} CCC {y} As Int32", 0, Associativity.LeftToRight, ItemCallback); uc.EvalStr("AAA()"); uc.EvalStr("BBB(9, 8, 7)"); uc.EvalStr("5 CCC 4");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
void ucalc_call ItemCallback(uCalcBase::Callback cb) {
cout << "Name: " << cb.Item().Name() << endl;
cout << "Data type: " << cb.Item().DataType().Name() << endl;
cout << "Param count: " << cb.Item().Count() << endl;
cout << "Procedure type: ";
if (cb.Item().IsProperty(ItemIs::Operator)) {
cout << "Operator" << endl;
} else if (cb.Item().IsProperty(ItemIs::Function)) {
cout << "Function" << endl;
}
cout << cb.Item().Text() << endl;
cout << cb.Item().Description() << endl;
cout << "---" << endl;
}
int main() {
uCalc uc;
uc.DefineFunction("AAA() As Double", ItemCallback).Description("Does this and that");
uc.DefineFunction("BBB(x, y, z) As String", ItemCallback).Description("Does something else");
uc.DefineOperator("{x} CCC {y} As Int32", 0, Associativity::LeftToRight, ItemCallback);
uc.EvalStr("AAA()");
uc.EvalStr("BBB(9, 8, 7)");
uc.EvalStr("5 CCC 4");
}
Name: aaa
Data type: double
Param count: 0
Procedure type: Function
Function: AAA() As Double
Does this and that
---
Name: bbb
Data type: string
Param count: 3
Procedure type: Function
Function: BBB(x, y, z) As String
Does something else
---
Name: ccc
Data type: int
Param count: 2
Procedure type: Operator
Operator: {x} CCC {y} As Int32
--- #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; void ucalc_call ItemCallback(uCalcBase::Callback cb) { cout << "Name: " << cb.Item().Name() << endl; cout << "Data type: " << cb.Item().DataType().Name() << endl; cout << "Param count: " << cb.Item().Count() << endl; cout << "Procedure type: "; if (cb.Item().IsProperty(ItemIs::Operator)) { cout << "Operator" << endl; } else if (cb.Item().IsProperty(ItemIs::Function)) { cout << "Function" << endl; } cout << cb.Item().Text() << endl; cout << cb.Item().Description() << endl; cout << "---" << endl; } int main() { uCalc uc; uc.DefineFunction("AAA() As Double", ItemCallback).Description("Does this and that"); uc.DefineFunction("BBB(x, y, z) As String", ItemCallback).Description("Does something else"); uc.DefineOperator("{x} CCC {y} As Int32", 0, Associativity::LeftToRight, ItemCallback); uc.EvalStr("AAA()"); uc.EvalStr("BBB(9, 8, 7)"); uc.EvalStr("5 CCC 4"); }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub ItemCallback(ByVal cb As uCalc.Callback)
Console.WriteLine($"Name: {cb.Item.Name}")
Console.WriteLine($"Data type: {cb.Item.DataType.Name}")
Console.WriteLine($"Param count: {cb.Item.Count}")
Console.Write("Procedure type: ")
If cb.Item.IsProperty(ItemIs.Operator) Then
Console.WriteLine("Operator")
ElseIf cb.Item.IsProperty(ItemIs.Function ) Then
Console.WriteLine("Function")
End If
Console.WriteLine(cb.Item.Text)
Console.WriteLine(cb.Item.Description)
Console.WriteLine("---")
End Sub
Public Sub Main()
Dim uc As New uCalc()
uc.DefineFunction("AAA() As Double", AddressOf ItemCallback).Description = "Does this and that"
uc.DefineFunction("BBB(x, y, z) As String", AddressOf ItemCallback).Description = "Does something else"
uc.DefineOperator("{x} CCC {y} As Int32", 0, Associativity.LeftToRight, AddressOf ItemCallback)
uc.EvalStr("AAA()")
uc.EvalStr("BBB(9, 8, 7)")
uc.EvalStr("5 CCC 4")
End Sub
End Module
Name: aaa
Data type: double
Param count: 0
Procedure type: Function
Function: AAA() As Double
Does this and that
---
Name: bbb
Data type: string
Param count: 3
Procedure type: Function
Function: BBB(x, y, z) As String
Does something else
---
Name: ccc
Data type: int
Param count: 2
Procedure type: Operator
Operator: {x} CCC {y} As Int32
--- Imports System Imports uCalcSoftware Public Module Program Public Sub ItemCallback(ByVal cb As uCalc.Callback) Console.WriteLine($"Name: {cb.Item.Name}") Console.WriteLine($"Data type: {cb.Item.DataType.Name}") Console.WriteLine($"Param count: {cb.Item.Count}") Console.Write("Procedure type: ") If cb.Item.IsProperty(ItemIs.Operator) Then Console.WriteLine("Operator") ElseIf cb.Item.IsProperty(ItemIs.Function ) Then Console.WriteLine("Function") End If Console.WriteLine(cb.Item.Text) Console.WriteLine(cb.Item.Description) Console.WriteLine("---") End Sub Public Sub Main() Dim uc As New uCalc() uc.DefineFunction("AAA() As Double", AddressOf ItemCallback).Description = "Does this and that" uc.DefineFunction("BBB(x, y, z) As String", AddressOf ItemCallback).Description = "Does something else" uc.DefineOperator("{x} CCC {y} As Int32", 0, Associativity.LeftToRight, AddressOf ItemCallback) uc.EvalStr("AAA()") uc.EvalStr("BBB(9, 8, 7)") uc.EvalStr("5 CCC 4") End Sub End Module