octave-maintainers
[Top][All Lists]
Advanced

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

Re: passing parameters to dynamically-linked functions


From: Thomas L. Scofield
Subject: Re: passing parameters to dynamically-linked functions
Date: Wed, 6 Aug 2008 08:50:27 -0400


What I chose to do was put all the optional parameters in a cell array (do that in the .m file) and pass that along to the dynamically linked file.  That's probably unnecessary work, but I got more comfortable with the Octave API in the process.  One thing I did not learn how to do is access a 2D cell array from within the dynamically linked function.

  std::string target = args (0).string_value ();
  Cell c = args (1).cell_value ();
  octave_idx_type numswitches = c.length ();
  octave_idx_type i = 0;
  while (i < c.nelem ()/2 && target.compare (c.elem(2*i).string_value ())) i++;  

seems to work fine (I've packed both the option itself, say "Quality", along with its setting, say 75, into the cell array one right after the other), but things did not seem to work when I had them side-by-side in a 2D array.  I had some other bugs along the way, so perhaps I ought to try it again.

At any rate, I was mainly concerned with whether there was some standard way to pass parameters like these along, and if there was wanted to follow the convention.

On Aug 5, 2008, at 11:18 PM, John W. Eaton wrote:

On 31-Jul-2008, Thomas L. Scofield wrote:

| 
| Parameters in Matlab are often passed in the manner
| 
|     functionName ( ..., 'parameterName', 'parameterValue' )
| 
| I am wondering if there is an established approach for organizing  
| such parameters, perhaps in a cell array(?), so that they are easily  
| passed on to and parsed within a dynamically-linked function.   
| Perhaps the kind of answer I am looking for goes like this: "for an  
| example, see the m-file ______ which accepts additional parameters  
| like these and then passes them along to the dynamically-linked  
| function _______."

I can't think of a specific example, but I think you would probably
want to call the dynamically linked function from the .m file with

  args = varargin(first_parameter_arg:end);
  dynamically_linked_function (..., args{:});

or similar so that the dynamically linked function just sees a normal
argument list in an octave_value_list object..

Does that help?

jwe



Thomas L. Scofield
--------------------------------------------------------
Associate Professor
Department of Mathematics and Statistics
Calvin College
--------------------------------------------------------


reply via email to

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