Octave logo Octave-Forge - Extra packages for GNU Octave
Home · Packages · Developers · Documentation · Function Reference · FAQ · Bugs · Mailing Lists · Links · SVN
  • Main Page
  • Classes
  • Files

examples/funcdemo.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2006, 2007 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or 
00008 modify it under the terms of the GNU General Public License 
00009 as published by the Free Software Foundation; either
00010 version 3  of the License, or (at your option) any later 
00011 version.
00012 
00013 Octave is distributed in the hope that it will be useful, 
00014 but WITHOUT ANY WARRANTY; without even the implied warranty
00015 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00016 See the GNU General Public License for more details.
00017 
00018 You should have received a copy of the GNU General Public 
00019 License along with Octave; see the file COPYING.  If not,
00020 see <http://www.gnu.org/licenses/>.
00021 
00022 */
00023 
00024 #include <octave/oct.h>
00025 #include <octave/parse.h>
00026 
00027 DEFUN_DLD (funcdemo, args, nargout, "Function Demo")
00028 {
00029   int nargin = args.length();
00030   octave_value_list retval;
00031 
00032   if (nargin < 2)
00033     print_usage ();
00034   else
00035     {
00036       octave_value_list newargs;
00037       for (octave_idx_type i = nargin - 1; i > 0; i--)
00038         newargs (i - 1) = args(i);
00039       if (args(0).is_function_handle ()
00040           || args(0).is_inline_function ())
00041         {
00042           octave_function *fcn = args(0).function_value ();
00043           if (! error_state)
00044             retval = feval (fcn, newargs, nargout);
00045         }
00046       else if (args(0).is_string ())
00047         {
00048           std::string fcn = args (0).string_value ();
00049           if (! error_state)
00050             retval = feval (fcn, newargs, nargout);
00051         }
00052       else
00053         error ("funcdemo: expected string,",
00054                " inline or function handle");
00055     }
00056   return retval;
00057 }
SourceForge.net Logo