help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calling Octave from C++


From: Tatsuro MATSUOKA
Subject: Re: Calling Octave from C++
Date: Tue, 27 Mar 2018 13:19:38 +0900 (JST)

********************
// THIS CODE IS WORKING
int qq =10;
int rr =15;
in(0) = octave_value(qq);
in(1) = octave_value(rr);
octave_value_list out = feval ("gcd", in, 1);
std::cout << out(0).int_value ()
and it prints the correct result = 5 the Greatest common disisor between 10
and 15

but if I run
// THIS CODE IN NOT WORKING
octave_value_list out = feval ("pp", in, 1);
where pp.m is a stupid Octave script which shuld disply the two numbers
(tested and working in the Octave environment)
*****************************
 
%pp.m
function y = pp()
    disp(5)
    disp(6)
end 

main (void)
{
  // Create interpreter.

  octave::interpreter interpreter;

  try
    {
      int status = interpreter.execute ();

      if (status != 0)
        {
          std::cerr << "creating embedded Octave interpreter failed!"
                    << std::endl;
          return status;
        }

        octave_value_list in;

        // THIS CODE IS WORKING
        int qq =10;
        int rr =15;
        in(0) = octave_value(qq);
        in(1) = octave_value(rr);
        octave_value_list out = octave::feval ("pp", in, 1);
        std::cout << out(0).int_value ()
                  << std::endl;
        //clean_up_and_exit(0);
      
    }
  catch (const octave::exit_exception& ex)
    {
      std::cerr << "Octave interpreter exited with status = "
                << ex.exit_status () << std::endl;
    }
  catch (const octave::execution_exception&)
    {
      std::cerr << "error encountered in Octave evaluator!" << std::endl;
    }

  return 0;
}

$ ./test_02
 5
 6
error: octave_base_value::double_value (): wrong type argument '<unknown type>'
error: octave_base_value::int_value (): wrong type argument '<unknown type>'
error encountered in Octave evaluator!

Perhaps I have make mistakes but does not hang.

Tatsuro



reply via email to

[Prev in Thread] Current Thread [Next in Thread]