octave-maintainers
[Top][All Lists]
Advanced

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

Re: Use Octave's interpreter in my C++ program...


From: John Swensen
Subject: Re: Use Octave's interpreter in my C++ program...
Date: Fri, 23 May 2008 10:14:07 -0400


On May 22, 2008, at 5:41 PM, John Swensen wrote:


On May 22, 2008, at 5:26 PM, address@hidden wrote:

Hello,
I would like to use Octave in a C++ multithreaded application. Is there something like this (see code below) in Octave so I can get an instance of Octave and use it throughout the life of my OctaveUser object? I'll even
take something close to this. :)

class OctaveUser
{
 private:
   OctaveInstance *p_oi;
 public:
  OctaveUser()
  {
      oi = OctaveFactory::createInstance();
  }
  void cppMethod()
  {
      Matrix m(2,2);
      m(0,0)=1; m(0,1)=2;
      m(1,0)=3; m(1,1)=4;
      oi.feval("invert", m);

      // call 'testFromCpp.m' file.
octave_value_list result = feval ("testFromCpp", octave_value (m),
1 );
      ...//do something with the value in C++
  }

  ~OctaveUser()
  {
      delete _oi;
  }
};

Thanks!
Molamini

So I went ahead and converted a class I had written for the Matlab Engine into a similar class for Octave. It is based on the pseudo- code I sent in my last email. I have attached a tgz file with the simple class and a test program. This is based on the concept of starting up octave_main() in embedded mode, pushing and pulling variables from the symbol table, and calling eval string to perform actions. Would the maintainers ever be interested in incorporating a more full-fledged version into Octave. As with the MEX interface, we could make the functions act like the Matlab Engine counterparts.

John Swensen

Attachment: OctaveEngine.tgz
Description: Binary data



reply via email to

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