uCalc API Version: 2.1.3-preview.2 Released: 6/17/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.
ReturnStr
Method
Product:
Class:
Sets the string return value for a user-defined callback function, passing it back to the uCalc expression engine.
Syntax
Parameters
Return
void
This method does not return a value to the host application; it communicates the return value back to the uCalc engine via the callback object.
Remarks
The ReturnStr method is the mechanism for sending a string result from a native callback function back to the uCalc evaluation engine. When a custom function defined with As String is called within an expression, this method must be used to provide its output.
⚙️ Type-Specific Returns
This method is specifically for returning string values. uCalc provides a family of type-safe return methods for other data types. Using the correct method ensures data integrity and avoids unnecessary type conversions.
- Return: For
Doublevalues (default numeric type). ReturnStr: ForStringvalues (this method).- ReturnBool: For
Booleanvalues. - ReturnInt16: For 16-bit integers.
- ReturnInt32: For 32-bit integers.
- ReturnInt64: For 64-bit integers.
💡 Comparative Analysis
Unlike a native return statement in C# or C++, which is a language-level control flow keyword, cb.ReturnStr() is a method call that interacts with the uCalc engine's internal state. It effectively places the provided value onto the evaluation stack, allowing the engine to continue processing the expression. This distinction is crucial: the callback function itself is typically void in the host language, and cb.ReturnStr() is the designated channel for communicating results back to the parser.
Examples
Returning a string (from a callback)
using uCalcSoftware;
var uc = new uCalc();
static void TwiceStr(uCalc.Callback cb) {
cb.ReturnStr(cb.ArgStr(1) + cb.ArgStr(1));
}
uc.DefineFunction("Twice(Txt As String) As String", TwiceStr);
Console.WriteLine(uc.EvalStr("Twice('Bye')"));
ByeBye using uCalcSoftware; var uc = new uCalc(); static void TwiceStr(uCalc.Callback cb) { cb.ReturnStr(cb.ArgStr(1) + cb.ArgStr(1)); } uc.DefineFunction("Twice(Txt As String) As String", TwiceStr); Console.WriteLine(uc.EvalStr("Twice('Bye')"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
void ucalc_call TwiceStr(uCalcBase::Callback cb) {
cb.ReturnStr(cb.ArgStr(1) + cb.ArgStr(1));
}
int main() {
uCalc uc;
uc.DefineFunction("Twice(Txt As String) As String", TwiceStr);
cout << uc.EvalStr("Twice('Bye')") << endl;
}
ByeBye #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; void ucalc_call TwiceStr(uCalcBase::Callback cb) { cb.ReturnStr(cb.ArgStr(1) + cb.ArgStr(1)); } int main() { uCalc uc; uc.DefineFunction("Twice(Txt As String) As String", TwiceStr); cout << uc.EvalStr("Twice('Bye')") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub TwiceStr(ByVal cb As uCalc.Callback)
cb.ReturnStr(cb.ArgStr(1) + cb.ArgStr(1))
End Sub
Public Sub Main()
Dim uc As New uCalc()
uc.DefineFunction("Twice(Txt As String) As String", AddressOf TwiceStr)
Console.WriteLine(uc.EvalStr("Twice('Bye')"))
End Sub
End Module
ByeBye Imports System Imports uCalcSoftware Public Module Program Public Sub TwiceStr(ByVal cb As uCalc.Callback) cb.ReturnStr(cb.ArgStr(1) + cb.ArgStr(1)) End Sub Public Sub Main() Dim uc As New uCalc() uc.DefineFunction("Twice(Txt As String) As String", AddressOf TwiceStr) Console.WriteLine(uc.EvalStr("Twice('Bye')")) End Sub End Module