changeset 32161:e04f7335e252

inputParser.m: Require that VALIDATOR input be a function handle. * inputParser.m (addParameter): Update documentation to state that VALIDATOR must be a function handle. Move validation of NAME to be first which reflects order of input parameters to function. Use is_function_handle() to verify VALIDATOR and throw an error if it is not. Add FIXME note about PartialMatchPriority being unimplemented.
author Rik <rik@octave.org>
date Wed, 21 Jun 2023 19:39:18 -0700
parents 93d3bcced10e
children 3815dfaf27e3
files scripts/miscellaneous/inputParser.m
diffstat 1 files changed, 8 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/miscellaneous/inputParser.m	Wed Jun 21 16:38:17 2023 -0400
+++ b/scripts/miscellaneous/inputParser.m	Wed Jun 21 19:39:18 2023 -0700
@@ -325,9 +325,8 @@
       ## @var{default} will be the value used when the parameter is not
       ## specified.
       ##
-      ## The optional argument @var{validator} is a function (handle or name)
-      ## that will return false or throw an error if the input @var{argname}
-      ## is invalid.
+      ## The optional argument @var{validator} is a function handle that will
+      ## return false or throw an error if the input @var{argname} is invalid.
       ##
       ## See @code{help inputParser} for examples.
       ##
@@ -337,14 +336,20 @@
         print_usage ();
       endif
 
+      this.validate_name ("Parameter", name);
+
       n_opt = numel (varargin);
 
       if (n_opt == 0 || n_opt == 2)
         val = inputParser.def_val;
       else  # n_opt is 1 or 3
         val = varargin{1};
+        if (! is_function_handle (val))
+          error ("inputParser.addParameter: VALIDATOR must be a function handle");
+        endif
       endif
 
+      ## FIXME: PartialMatchPriority is parsed, but not implemented
       if (n_opt == 0 || n_opt == 1)
         match_priority = 1;
       else  # n_opt is 2 or 3
@@ -357,7 +362,6 @@
                             "PartialMatchPriority");
       endif
 
-      this.validate_name ("Parameter", name);
       if (iscell (def))
         ## Accept cell default values (bug #64305).
         this.Parameter(end+1) = struct ("name", name, "def", {def}, "val", val);