A simple `Describe` function that uses `ByHandle` to inspect an argument's name and data type.

ID: 1236

				
					using uCalcSoftware;

var uc = new uCalc();

static void DescribeArg(uCalc.Callback cb) {
   // Retrieve the Item object for the first argument.
   var item = cb.ArgItem(1);

   // Inspect the item's metadata.
   var name = item.Name;
   if (name == "") {
      name = "(literal)";
   }

   Console.WriteLine($"  - Name: {name}, Type: {item.DataType.Name}");
}

uc.DefineFunction("Describe(ByHandle arg As AnyType)", DescribeArg);
uc.DefineVariable("my_var = 100");

Console.WriteLine("Inspecting a variable:");
uc.Eval("Describe(my_var)");

Console.WriteLine("Inspecting a literal value:");
uc.Eval("Describe(123.45)");

Console.WriteLine("Inspecting a string value:");
uc.EvalStr("Describe('abc xyz')");
				
			
Inspecting a variable:
  - Name: my_var, Type: double
Inspecting a literal value:
  - Name: (literal), Type: double
Inspecting a string value:
  - Name: (literal), Type: string
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

void ucalc_call DescribeArg(uCalcBase::Callback cb) {
   // Retrieve the Item object for the first argument.
   auto item = cb.ArgItem(1);

   // Inspect the item's metadata.
   auto name = item.Name();
   if (name == "") {
      name = "(literal)";
   }

   cout << "  - Name: " << name << ", Type: " << item.DataType().Name() << endl;
}
int main() {
   uCalc uc;
   uc.DefineFunction("Describe(ByHandle arg As AnyType)", DescribeArg);
   uc.DefineVariable("my_var = 100");

   cout << "Inspecting a variable:" << endl;
   uc.Eval("Describe(my_var)");

   cout << "Inspecting a literal value:" << endl;
   uc.Eval("Describe(123.45)");

   cout << "Inspecting a string value:" << endl;
   uc.EvalStr("Describe('abc xyz')");
}
				
			
Inspecting a variable:
  - Name: my_var, Type: double
Inspecting a literal value:
  - Name: (literal), Type: double
Inspecting a string value:
  - Name: (literal), Type: string
				
					Imports System
Imports uCalcSoftware
Public Module Program
   
   Public Sub DescribeArg(ByVal cb As uCalc.Callback)
      '// Retrieve the Item object for the first argument.
      Dim item = cb.ArgItem(1)
      
      '// Inspect the item's metadata.
      Dim name = item.Name
      If Len(name) = 0 Then
         name = "(literal)"
      End If
      
      Console.WriteLine($"  - Name: {name}, Type: {item.DataType.Name}")
   End Sub
   Public Sub Main()
      Dim uc As New uCalc()
      uc.DefineFunction("Describe(ByHandle arg As AnyType)", AddressOf DescribeArg)
      uc.DefineVariable("my_var = 100")
      
      Console.WriteLine("Inspecting a variable:")
      uc.Eval("Describe(my_var)")
      
      Console.WriteLine("Inspecting a literal value:")
      uc.Eval("Describe(123.45)")
      
      Console.WriteLine("Inspecting a string value:")
      uc.EvalStr("Describe('abc xyz')")
   End Sub
End Module
				
			
Inspecting a variable:
  - Name: my_var, Type: double
Inspecting a literal value:
  - Name: (literal), Type: double
Inspecting a string value:
  - Name: (literal), Type: string