help-octave
[Top][All Lists]

 From: geraint Subject: Re: about "Dynamically Linked Functions" Date: Wed, 9 Apr 2003 12:51:50 +0000

```> From: myong <address@hidden>
> Date: Wed 09/Apr/2003 09:03 GMT
>
> functions, especially the passing o farguments.
>

A good starting place is http://octave.sourceforge.net/coda/coda.html. It is
also highly recommended that you take a look at the examples included in the
octave source code, such as oregenator.cc.

In answer to the specific question about argument passing, arguments are passed
to dynamically loaded functions packaged within an octave_value_list, as the
second argument to the function. The objects then need to be extracted into
appropriate containers (e.g. column_vector_value) before use. An
octave_value_list is also returned from the function, so it is possible to
return more than one object back to Octave.

The following example may serve to illustrate the method.

== myoct.cc ==

#include <octave/oct.h>

DEFUN_DLD (myoct, args, , "dummy function")
{
octave_value_list retval;

int nargin = args.length();

if (nargin != 2)
error("Require 2 input arguments");

ColumnVector a = args(0).column_vector_value();
ColumnVector b = args(1).column_vector_value();

if (a.length() != b.length())
error("Input vectors not of same length");

ColumnVector c = a + b;
ColumnVector d = a - b;

retval(0) = c;
retval(1) = d;

return retval;
}

======
\$ mkoctfile myoct.cc
\$ octave -q
octave:1> [ c , d ] = myoct ( [ 1 ; 2 ] , [ 3 ; 4 ] )
c =

4
6

d =

-2
-2

octave:2>

Hope this helps,
Geraint.

__________________________________________________________________________
Join Freeserve http://www.freeserve.com/time/

Winner of the 2003 Internet Service Providers' Association awards for Best
Unmetered ISP and Best Consumer Application.

-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------

```