changeset 9331:a76f391a3d02

set up proper nargout for call to subsref method
author Jaroslav Hajek <highegg@gmail.com>
date Thu, 11 Jun 2009 12:25:36 +0200
parents e903c92d2f02
children bf6da2fbfa4e
files src/ChangeLog src/ov-class.cc
diffstat 2 files changed, 26 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Thu Jun 11 11:12:02 2009 +0200
+++ b/src/ChangeLog	Thu Jun 11 12:25:36 2009 +0200
@@ -1,3 +1,8 @@
+2009-06-11  Jaroslav Hajek  <highegg@gmail.com>
+
+	* ov-class.cc (subsref): Set up proper nargout for call to subsref
+	method.
+
 2009-06-10  Jaroslav Hajek  <highegg@gmail.com>
 
 	* ov-base.cc (octave_base_value::numel (const octave_value_list&),
--- a/src/ov-class.cc	Thu Jun 11 11:12:02 2009 +0200
+++ b/src/ov-class.cc	Thu Jun 11 12:25:36 2009 +0200
@@ -446,7 +446,27 @@
 	  count++;
 	  args(0) = octave_value (this);
 
-	  return feval (meth.function_value (), args, nargout);
+          bool maybe_cs_list_query = (type[0] == '.' || type[0] == '{'
+                                      || (type.length () > 1 && type[0] == '('
+                                          && type[1] == '.'));
+
+          if (nargout == 1 && maybe_cs_list_query)
+            {
+              // Set up a proper nargout for the subsref call by calling numel.
+              octave_value_list tmp;
+              if (type[0] != '.') tmp = idx.front ();
+              octave_idx_type true_nargout = numel (tmp);
+              if (! error_state)
+                {
+                  tmp = feval (meth.function_value (), args, true_nargout);
+                  if (true_nargout != 1)
+                    retval(0) = octave_value (tmp, true);
+                  else
+                    retval = tmp;
+                }
+            }
+          else
+            retval = feval (meth.function_value (), args, nargout);
 	}
       else
 	{