using uCalcSoftware;

var uc = new uCalc();

static void SumIfType(uCalc.Callback cb) {
   var typeName = cb.ArgStr(1);
   double total = 0;
   string totalStr = "";
   var i = 0;

   // Loop through all arguments starting from the second one.
   for ( i = 2; i <= cb.ArgCount(); i++) {
      var item = cb.ArgItem(i);
      // Check if the argument's data type name matches.
      if (item.DataType.Name == "double") {
         total = total + item.Value();
      } else if (item.DataType.Name == "string") {
         totalStr = totalStr + item.ValueStr();
      }
   }

   if (typeName == "double") {
      totalStr = total.ToString();
   }
   cb.ReturnStr(totalStr);
}

// Define the variadic function.
uc.DefineFunction("SumIfType(typeName As String, ByHandle other As AnyType ...) As String", SumIfType);

// This call will sum only the double values (5.0 and 10.123456), ignoring the integer.
Console.WriteLine(uc.EvalStr("SumIfType('double', 5.0, 'Hello ', 10.123456, 'world!')"));

// This call will concatinate only the string values.
Console.WriteLine(uc.EvalStr("SumIfType('string', 5.0, 'Hello ', 10.123456, 'world!')"));