Imports System
Imports uCalcSoftware
Public Module Program
   
   Public Sub SwapValues(ByVal cb As uCalc.Callback)
      '// Get the item handles for the two variables passed by reference
      Dim item1 = cb.ArgItem(1)
      Dim item2 = cb.ArgItem(2)
      
      '// Use the item's DataType object to perform a highly efficient, pointer-based swap
      item1.DataType.SwapScalarValues(item1.ValueAddr(), item2.ValueAddr())
   End Sub
   Public Sub Main()
      Dim uc As New uCalc()
      '// Define the Swap function with ByRef parameters
      uc.DefineFunction("Swap(ByHandle a, ByHandle b)", AddressOf SwapValues)
      
      '// Define the variables to be swapped
      uc.DefineVariable("x = 100")
      uc.DefineVariable("y = 200")
      
      Console.WriteLine($"Before: x = {uc.Eval("x")}, y = {uc.Eval("y")}")
      
      '// Call the swap function
      uc.Eval("Swap(x, y)")
      
      Console.WriteLine($"After:  x = {uc.Eval("x")}, y = {uc.Eval("y")}")
   End Sub
End Module