@@ -404,29 +404,37 @@ void MathEval<DoubleType>::EvaluateTclMathFunc(const std::string &func, std::vec
404404
405405 dsAssert (it != tclMathFuncMap_.end (), " UNEXPECTED" );
406406
407- const size_t tclcount = it->second ;
407+ const size_t tclcount = ( it->second ). second ;
408408
409409 const size_t cnt = vvals.size ();
410410
411- if (tclcount == cnt)
411+ std::vector<ObjectHolder> tclObjVector;
412+
413+ if (tclcount != cnt)
414+ {
415+ std::ostringstream os;
416+ os << " function registered with \" " << tclcount << " \" arguments and \" " << cnt << " \" were provided: \" " << func << " \" " ;
417+ error += os.str ();
418+ }
419+ else
412420 {
421+ ObjectHolder procedure = (it->second ).first ;
422+
413423 Interpreter MyInterp;
414424 // // put the objects in here
415- tclObjVector.resize (cnt + 1 );
416-
417- tclObjVector[0 ] = ObjectHolder (func);
425+ tclObjVector.resize (cnt);
418426
419427 size_t numvecs = 0 ;
420428 size_t numelems = 0 ;
421429 for (size_t i = 0 ; i < cnt; ++i)
422430 {
423431 if (vvals[i] == nullptr )
424432 {
425- tclObjVector[i + 1 ] = ObjectHolder (static_cast <double >(dvals[i]));
433+ tclObjVector[i] = ObjectHolder (static_cast <double >(dvals[i]));
426434 }
427435 else
428436 {
429- tclObjVector[i + 1 ].clear ();
437+ tclObjVector[i].clear ();
430438 ++numvecs;
431439 if (numelems == 0 )
432440 {
@@ -450,11 +458,11 @@ void MathEval<DoubleType>::EvaluateTclMathFunc(const std::string &func, std::vec
450458
451459 if (isvec)
452460 {
453- tclObjVector[i+ 1 ] = ObjectHolder (static_cast <double >(vvals[i]->operator [](j)));
461+ tclObjVector[i] = ObjectHolder (static_cast <double >(vvals[i]->operator [](j)));
454462 }
455463 }
456464
457- bool ok = MyInterp.RunCommand (tclObjVector);
465+ bool ok = MyInterp.RunCommand (procedure, tclObjVector);
458466
459467 if (ok)
460468 {
@@ -480,12 +488,6 @@ void MathEval<DoubleType>::EvaluateTclMathFunc(const std::string &func, std::vec
480488 }
481489 }
482490 }
483- else
484- {
485- std::ostringstream os;
486- os << " function registered with \" " << tclcount << " \" arguments and \" " << cnt << " \" were provided: \" " << func << " \" " ;
487- error += os.str ();
488- }
489491}
490492
491493template <typename DoubleType>
@@ -523,12 +525,29 @@ void MathEval<DoubleType>::EvaluateMathFunc(const std::string &func, std::vector
523525 }
524526}
525527
528+ template <typename DoubleType>
529+ bool MathEval<DoubleType>::AddTclMath(const std::string &funcname, ObjectHolder procedure, size_t numargs, std::string &error)
530+ {
531+ if (!procedure.IsCallable ())
532+ {
533+ std::ostringstream os;
534+ os << " procedure given for \" " << funcname << " \" is not callable" ;
535+ error += os.str ();
536+ }
537+ else
538+ {
539+ tclMathFuncMap_[funcname] = std::make_pair (procedure, numargs);
540+ }
541+ return error.empty ();
542+ }
543+ #if 0
526544template <typename DoubleType>
527545void MathEval<DoubleType>::AddTclMath(const std::string &funcname, size_t numargs)
528546{
529547 ///Really need to make sure number of arguments make sense in tcl api
530548 tclMathFuncMap_[funcname] = numargs;
531549}
550+ #endif
532551
533552template <typename DoubleType>
534553void MathEval<DoubleType>::RemoveTclMath(const std::string &funcname)
0 commit comments