On 12/18/2012 07:46 AM, John W. Eaton wrote:
> On 17-Dec-2012, Michael Goffioul wrote:
>
> | On Mon, Dec 17, 2012 at 5:43 PM, Rik <
address@hidden> wrote:
> |
> | 12/17/12
> |
> | John,
> |
> | I have an octave_value that is the input to a DEFUN function. I have
> | verified that the object is in fact of class "octave_java". Is there an
> | easy way to interpret the octave_value as being of class octave_java and
> | calling a method from the octave_java class?
> |
> | Or is the real, but longer way, to declare a new function in ov-base.h
> | that
> | performs the interpretation. And then in the DEFUN function I need to
> | declare a new instance of the octave_java class.
> |
> | octave_java oct_jobj = args(0).octave_java_value ();
> | oct_jobj.method_name ();
>
> I would not expose the representation class as a value. If you want
> to go this route, then look at the way the octave_function_value
> method works to return the rep pointer as a pointer to an
> octave_function object.
>
> Which functions from the octave_java class do you want to expose?
>
> | The java.cc code used to do something like (see TO_JAVA macro):
> |
> | dynamic_cast<octave_java*> ((obj).internal_rep ())
> |
> | Not very clean, but it was only used internally anyway. This also returns a
> | pointer, not a plain object. Having a method octave_value::octave_java_value()
> | returning a plain octave_java is technically possible: the octave_java class
> | handles copy, by referencing the underlying Java object.
>
> Right, this is a reasonable way to do the job.