1 ## Copyright (C) 2012 Carnë Draug
3 ## This file is part of Octave.
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {} narginchk (@var{minargs}, @var{maxargs})
21 ## Check for correct number of arguments or generate an error message if
22 ## the number of arguments in the calling function is outside the range
23 ## @var{minargs} and @var{maxargs}. Otherwise, do nothing.
25 ## Both @var{minargs} and @var{maxargs} need to be scalar numeric
26 ## values. Zero, Inf and negative values are all allowed, and
27 ## @var{minargs} and @var{maxargs} may be equal.
29 ## Note that this function evaluates @code{nargin} on the caller.
31 ## @seealso{nargchk, nargoutchk, error, nargout, nargin}
34 ## Author: Carnë Draug <carandraug+dev@gmail.com>
36 function narginchk (minargs, maxargs)
40 elseif (!isnumeric (minargs) || !isscalar (minargs))
41 error ("minargs must be a numeric scalar");
42 elseif (!isnumeric (maxargs) || !isscalar (maxargs))
43 error ("maxargs must be a numeric scalar");
44 elseif (minargs > maxargs)
45 error ("minargs cannot be larger than maxargs")
48 args = evalin ("caller", "nargin;");
51 error ("not enough input arguments");
52 elseif (args > maxargs)
53 error ("too many input arguments");
58 %!function f (nargs, varargin)
59 %! narginchk (nargs(1), nargs(2));
62 %!error <too many input arguments> f([0,0])
63 %!error <not enough input arguments> f([3, 3], 1)
69 %! f([1,5], 2, 3, 4, 5)