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:02:02 +0900 (JST)

----- Original Message -----

> From: Mike Miller 
> To: help-octave
> Cc: 
> Date: 2018/3/27, Tue 09:57
> Subject: Re: Calling Octave from C++
> 
> On Tue, Mar 27, 2018 at 09:16:41 +0900, Tatsuro MATSUOKA wrote:
>>  #include <iostream>
>>  #include <octave/oct.h>
>>  #include <octave/octave.h>
>>  #include <octave/parse.h>
>>  #include <octave/interpreter.h>
>> 
>>  int
>>  main (void)
>>  {
>>    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 = feval ("gcd", in, 1);
>>    std::cout << out(0).int_value ();
>>    clean_up_and_exit(0);
>>  }
>> 
>>  Still hang for me on current stable source (HG-ID 231847364696 upcoming 
> 4.4).
> 
> This is not surprising at all because you haven't initialized the Octave
> interpreter. This is not a complete example.
> 
> Please compare this code with examples/code/embedded.cc
> 
>   
> https://hg.savannah.gnu.org/hgweb/octave/file/baa7e37453b1/examples/code/embedded.cc
> 
> And compare the equivalent example for Octave 4.2
> 
>   
> https://hg.savannah.gnu.org/hgweb/octave/file/ea09770fb556/examples/code/embedded.cc
> 
> -- 
> mike

Thanks! Worked as expected.

Tatsuro

#include <iostream>
#include <octave/oct.h>
#include <octave/octave.h>
#include <octave/parse.h>
#include <octave/interpreter.h>

int
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 ("gcd", 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;
}



reply via email to

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