From 720c28f1ed068b17a5df89e2571a1208b79f5e22 Mon Sep 17 00:00:00 2001 From: Markus Friedrich Date: Sun, 18 Sep 2022 19:40:37 +0200 Subject: [PATCH 1/2] Reenable and fix octave horzcat operator test This test was disabled with 0a0743f25cc0bbb395d03a27ac62887c8cbee5cf since it fails with octave 7.2.0 The test function horzcat now uses a variable length argument list to fix this. Before octave 7 it seems to be possible to call a N-argument octave function with > N arguments without any error. With octave 7 this seems no longer to be possible which caused the test failure. --- Examples/octave/operator/@swig_ref/horzcat.m | 9 ++++++--- Examples/octave/operator/runme.m | 5 ++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Examples/octave/operator/@swig_ref/horzcat.m b/Examples/octave/operator/@swig_ref/horzcat.m index 00fdfd5ce..6d4a55b20 100644 --- a/Examples/octave/operator/@swig_ref/horzcat.m +++ b/Examples/octave/operator/@swig_ref/horzcat.m @@ -1,6 +1,9 @@ % test octaves concatenation operator -function ret=horzcat(a, b) - % return the concatenation of two ComplexVal values as a cell array. +function ret=horzcat(varargin) + % return the concatenation of several ComplexVal values as a cell array. % (not really useful but it tests the concatenation of swig_ref objects) - ret={a, b}; + ret={}; + for i=1:length(varargin) + ret{i}=varargin{i}; + end end diff --git a/Examples/octave/operator/runme.m b/Examples/octave/operator/runme.m index 41c2c14a7..ff8b594da 100644 --- a/Examples/octave/operator/runme.m +++ b/Examples/octave/operator/runme.m @@ -47,6 +47,5 @@ if swig_octave_prereq(3,8,0) endif # concatenation operator, note: calls @swig_ref/horzcat.m -# g = [a, b, c]; -# printf("g = %s\n",disp(g)); -# Above temporarily removed as broken in octave-7.2.0, see https://github.com/swig/swig/issues/2353 +g = [a, b, c]; +printf("g = %s\n",disp(g)); From d1b7765838c2145e8c6fb545d46075298f2ee2a8 Mon Sep 17 00:00:00 2001 From: Markus Friedrich Date: Sun, 18 Sep 2022 20:19:39 +0200 Subject: [PATCH 2/2] Extended the documentation for octave operator overloading Octave has more operators than C++. These operators can be overloaded for the type swig_ref using the standard Octave Object Oriented Programming mechanism. This is now added to the documentation. --- Doc/Manual/Octave.html | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Doc/Manual/Octave.html b/Doc/Manual/Octave.html index de39a1d96..b5168b899 100644 --- a/Doc/Manual/Octave.html +++ b/Doc/Manual/Octave.html @@ -625,6 +625,16 @@ On the C++ side, the default mappings are as follows: Octave can also utilise friend (i.e. non-member) operators with a simple %rename: see the example in the Examples/octave/operator directory.

+

+Octave has several operators for which no corresponding C++ operators exist. For example, the Octave code +

+
+x=[a,b,c];
+
+

+calls the Octave operator horzcat of the class of a. Hence, if a is of type swig_ref you can write an overload for this operator for your wrapped C++ class by placing a file @swig_ref/horzcat.m in the Octave load path (like for every Octave class, see Creating a Class). This Octave function file is then called whenever the above Octave code is executed for a variable of type swig_ref. +

+

30.3.10 Class extension with %extend