changeset 76:ba609c4d77db

load/unload_package, workaround undefined values bug
author Jaroslav Hajek <highegg@gmail.com>
date Wed, 16 Sep 2009 07:31:25 +0200
parents b0991511a16d
children fb227ceacc65
files ChangeLog octave_to_python.cc package/pytave.py
diffstat 3 files changed, 21 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Sep 15 11:23:36 2009 +0200
+++ b/ChangeLog	Wed Sep 16 07:31:25 2009 +0200
@@ -1,3 +1,9 @@
+2009-09-16  Jaroslav Hajek  <highegg@gmail.com>
+
+	* package/pytave.py (load_package, unload_package): New funcs.
+	* octave_to_python.cc: Workaround for return values bug in 
+	Octave <= 3.2.3.
+
 2009-09-15  Jaroslav Hajek  <highegg@gmail.com>
 
 	* octave_to_python.cc: Move #include of arrayobjectdefs after
--- a/octave_to_python.cc	Tue Sep 15 11:23:36 2009 +0200
+++ b/octave_to_python.cc	Wed Sep 16 07:31:25 2009 +0200
@@ -306,6 +306,13 @@
                            const octave_value_list &octave_list) {
       boost::python::list seq;
       int length = octave_list.length();
+
+      // FIXME: due to bugs in Octave 3.2.3 and earlier, lists returned from
+      // eval_string and feval may be padded by trailing undefined values.
+      // Fix is already upstream, so this may be eventually removed.
+      while (length > 0 && octave_list(length-1).is_undefined())
+         length--;
+
       for (int i = 0; i < length; i++) {
          boost::python::object py_object;
          octvalue_to_pyobj(py_object, octave_list(i));
--- a/package/pytave.py	Tue Sep 15 11:23:36 2009 +0200
+++ b/package/pytave.py	Wed Sep 16 07:31:25 2009 +0200
@@ -232,6 +232,14 @@
 	"""See Octave documentation"""
 	return _pytave.feval(1, "path", paths)[0]
 
+def load_package(pkg_name):
+    """Equivalent to pkg load. See Octave documentation."""
+    return _pytave.feval(0, "pkg", ("load", pkg_name))
+
+def unload_package(pkg_name):
+    """Equivalent to pkg unload. See Octave documentation."""
+    return _pytave.feval(0, "pkg", ("unload", pkg_name))
+
 class _VariablesDict(UserDict.DictMixin):
 	def __init__(self, global_variables, native=False):
 		self.global_variables = global_variables