/* Copyright (c) 2001-2004 by SoftIntegration, Inc. All Rights Reserved */
#include <ch.h>
#include "sum2.h"

EXPORTCH double sum2_chdl(void *varg){
  ChInterp_t interp;
  ChVaList_t ap;

  int count, param, ii, ii2;
  float ff, ff2;
  double dd, dd2, retval = 0;

  Ch_VaStart(interp, ap, varg);
  param = Ch_VaArg(interp, ap, int);

  count = Ch_VaCount(interp, ap);
  if(count == 0)
     retval = sum2(param);

  if(count >= 1) {
      ii = Ch_VaArg(interp, ap, int);
      if(count == 1)
        retval = sum2(param, ii);
  }

  if(count >= 2) {
      ii2 = Ch_VaArg(interp, ap, int);
      if(count == 2)
        retval = sum2(param, ii, ii2);
  }

  if(count >= 3) {
      ff = Ch_VaArg(interp, ap, float);
      if(count == 3)
        retval = sum2(param, ii, ii2, ff);
  }

  if(count >= 4) {
      ff2 = Ch_VaArg(interp, ap, float);
      if(count == 4)
        retval = sum2(param, ii, ii2, ff, ff2);
  }

  if(count >= 5) {
      dd = Ch_VaArg(interp, ap, double);
      if(count == 5)
        retval = sum2(param, ii, ii2, ff, ff2, dd);
  }

  if(count >= 6) {
      dd2 = Ch_VaArg(interp, ap, double);
      if(count == 6)
        retval = sum2(param, ii, ii2, ff, ff2, dd, dd2);
  }

  Ch_VaEnd(interp, ap);
  return retval;
}
