How to instantiate a user-class from octfile?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to instantiate a user-class from octfile?

Colin Macdonald-2
Hi all,

Suppose I have an m-file classdef "Myclass" which I can instantiate using:

x = Myclass("hello")

How would I make `x` within an oct-file (in C++)?

thanks,
Colin

Reply | Threaded
Open this post in threaded view
|

Re: How to instantiate a user-class from octfile?

Mike Miller-4
On Thu, May 19, 2016 at 23:47:12 -0700, Colin Macdonald wrote:
> Hi all,
>
> Suppose I have an m-file classdef "Myclass" which I can instantiate using:
>
> x = Myclass("hello")
>
> How would I make `x` within an oct-file (in C++)?

A way would be something like

  octave_value_list ret = feval ("Myclass", ovl ("hello"), 1);
  octave_value x = ret(0);

I don't know if it's the only way, but pretty straightforward.

--
mike

Reply | Threaded
Open this post in threaded view
|

Re: How to instantiate a user-class from octfile?

Colin Macdonald-2
On 20/05/16 17:43, Mike Miller wrote:
> A way would be something like
>
>   octave_value_list ret = feval ("Myclass", ovl ("hello"), 1);
>   octave_value x = ret(0);
>
> I don't know if it's the only way, but pretty straightforward.

Thanks, works great.  For the record, to get feval I needed:

  #include <octave/parse.h>

thanks,
Colin