Demonstrates a practical callback that retrieves a 'host application setting', simulating I/O or access to native configuration.

ID: 1243

				
					using uCalcSoftware;

var uc = new uCalc();

static void GetSetting(uCalc.Callback cb) {
   // Get the name of the setting to retrieve.
   var settingName = cb.ArgStr(1);

   // In a real app, this would read from a config file, database, or registry.
   // We simulate it by evaluating another variable in the parent uCalc context.
   var value = cb.uCalc.EvalStr(settingName);

   cb.ReturnStr(value);
}

// Simulate a host application's configuration store using uCalc variables.
uc.DefineVariable("AppName = 'uCalc Demo'");
uc.DefineVariable("Version = '1.2.3'");

// Define the function that provides a bridge to the 'host'.
uc.DefineFunction("GetHostSetting(name As String) As String", GetSetting);

// Use the custom function to build a string from the host settings.
Console.WriteLine(uc.EvalStr("GetHostSetting('AppName') + ' v' + GetHostSetting('Version')"));
				
			
uCalc Demo v1.2.3
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

void ucalc_call GetSetting(uCalcBase::Callback cb) {
   // Get the name of the setting to retrieve.
   auto settingName = cb.ArgStr(1);

   // In a real app, this would read from a config file, database, or registry.
   // We simulate it by evaluating another variable in the parent uCalc context.
   auto value = cb.uCalc().EvalStr(settingName);

   cb.ReturnStr(value);
}
int main() {
   uCalc uc;
   // Simulate a host application's configuration store using uCalc variables.
   uc.DefineVariable("AppName = 'uCalc Demo'");
   uc.DefineVariable("Version = '1.2.3'");

   // Define the function that provides a bridge to the 'host'.
   uc.DefineFunction("GetHostSetting(name As String) As String", GetSetting);

   // Use the custom function to build a string from the host settings.
   cout << uc.EvalStr("GetHostSetting('AppName') + ' v' + GetHostSetting('Version')") << endl;
}
				
			
uCalc Demo v1.2.3
				
					Imports System
Imports uCalcSoftware
Public Module Program
   
   Public Sub GetSetting(ByVal cb As uCalc.Callback)
      '// Get the name of the setting to retrieve.
      Dim settingName = cb.ArgStr(1)
      
      '// In a real app, this would read from a config file, database, or registry.
      '// We simulate it by evaluating another variable in the parent uCalc context.
      Dim value = cb.uCalc.EvalStr(settingName)
      
      cb.ReturnStr(value)
   End Sub
   Public Sub Main()
      Dim uc As New uCalc()
      '// Simulate a host application's configuration store using uCalc variables.
      uc.DefineVariable("AppName = 'uCalc Demo'")
      uc.DefineVariable("Version = '1.2.3'")
      
      '// Define the function that provides a bridge to the 'host'.
      uc.DefineFunction("GetHostSetting(name As String) As String", AddressOf GetSetting)
      
      '// Use the custom function to build a string from the host settings.
      Console.WriteLine(uc.EvalStr("GetHostSetting('AppName') + ' v' + GetHostSetting('Version')"))
   End Sub
End Module
				
			
uCalc Demo v1.2.3