changeset 23845:3cace95ce563

* oct-parse.in.yy (source_file): Restore source-ing of function files.
author John W. Eaton <jwe@octave.org>
date Tue, 08 Aug 2017 19:45:47 -0400
parents ca4535a6ee9f
children 12203140139f
files libinterp/parse-tree/oct-parse.in.yy
diffstat 1 files changed, 18 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/parse-tree/oct-parse.in.yy	Tue Aug 08 18:22:30 2017 -0400
+++ b/libinterp/parse-tree/oct-parse.in.yy	Tue Aug 08 19:45:47 2017 -0400
@@ -4816,6 +4816,10 @@
 
 namespace octave
 {
+  // Execute the contents of a script file.  For compatibility with
+  // Matlab, also execute a function file by calling the function it
+  // defines with no arguments and nargout = 0.
+
   void
   source_file (const std::string& file_name, const std::string& context,
                bool verbose, bool require_file, const std::string& warn_for)
@@ -4909,12 +4913,15 @@
     symbol_table& symtab = __get_symbol_table__ ("source_file");
     octave_value ov_code = symtab.find (symbol);
 
-    if (ov_code.is_user_script ())
+    // For compatibility with Matlab, accept both scripts and
+    // functions.
+
+    if (ov_code.is_user_code ())
       {
-        octave_user_script *script = ov_code.user_script_value ();
-
-        if (! script
-            || (sys::canonicalize_file_name (script->fcn_file_name ())
+        octave_user_code *code = ov_code.user_code_value ();
+
+        if (! code
+            || (sys::canonicalize_file_name (code->fcn_file_name ())
                 != full_name))
           {
             // Wrong file, so load it below.
@@ -4945,11 +4952,12 @@
           }
       }
 
-    // Return or error if we don't have a valid script
+    // Return or error if we don't have a valid script or function.
+
     if (ov_code.is_undefined ())
       return;
 
-    if (! ov_code.is_user_script ())
+    if (! ov_code.is_user_code ())
       error ("source: %s is not a script", full_name.c_str ());
 
     if (verbose)
@@ -4958,9 +4966,9 @@
         std::cout.flush ();
       }
 
-    octave_user_script *script = ov_code.user_script_value ();
-
-    script->call (tw, 0);
+    octave_user_code *code = ov_code.user_code_value ();
+
+    code->call (tw, 0, octave_value_list ());
 
     if (verbose)
       std::cout << "done." << std::endl;