diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2010-05-11 22:53:33 +0000 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2010-05-11 22:53:33 +0000 |
commit | 3cf41050b56fcf5f3bea0d4368825e93e2111604 (patch) | |
tree | 204475d2b4c5e3b9d9393ade4756b7c45622d3b5 | |
parent | e854baabec278d2235f4cef3cee69ae113ab0c64 (diff) | |
download | swig-3cf41050b56fcf5f3bea0d4368825e93e2111604.tar.gz |
Fix Octave C enums wrapping when the generated code is C++ compiled
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12022 626c5289-ae23-0410-ae9c-e8d60b6d4f22
-rw-r--r-- | Doc/Manual/Octave.html | 20 | ||||
-rw-r--r-- | Source/Modules/octave.cxx | 3 | ||||
-rw-r--r-- | Source/Modules/typepass.cxx | 6 |
3 files changed, 21 insertions, 8 deletions
diff --git a/Doc/Manual/Octave.html b/Doc/Manual/Octave.html index 7409d78f1..63663a474 100644 --- a/Doc/Manual/Octave.html +++ b/Doc/Manual/Octave.html @@ -58,17 +58,18 @@ Also, there are a dozen or so examples in the Examples/octave directory, and hun <p> -The current SWIG implemention is based on Octave 2.9.12. Support for other versions (in particular the recent 3.0) has not been tested, nor has support for any OS other than Linux. +The SWIG implemention was first based on Octave 2.9.12, so this is the minimum version required. Testing has only been done on Linux. </p> <H2><a name="Octave_nn3"></a>27.2 Running SWIG</H2> <p> -Let's start with a very simple SWIG interface file: +Let's start with a very simple SWIG interface file, example.i: </p> -<div class="code"><pre>%module example +<div class="code"><pre> +%module example %{ #include "example.h" %} @@ -76,13 +77,20 @@ int gcd(int x, int y); extern double Foo; </pre></div> <p> -To build an Octave module, run SWIG using the <tt>-octave</tt> option. The <tt>-c++</tt> option is required (for now) as Octave itself is written in C++ and thus the wrapper code must also be. +To build an Octave module when wrapping C code, run SWIG using the <tt>-octave</tt> option: </p> +<div class="shell"><pre>$ swig -octave example.i </pre></div> + +<p> +The <tt>-c++</tt> option is also required when wrapping C++ code: +</p> + + <div class="shell"><pre>$ swig -octave -c++ example.i </pre></div> <p> -This creates a C/C++ source file <tt>example_wrap.cxx</tt>. The generated C++ source file contains the low-level wrappers that need to be compiled and linked with the rest of your C/C++ application (in this case, the gcd implementation) to create an extension module. +This creates a C++ source file <tt>example_wrap.cxx</tt>. A C++ file is generated even when wrapping C code as Octave is itself written in C++ and requires wrapper code to be in the same language. The generated C++ source file contains the low-level wrappers that need to be compiled and linked with the rest of your C/C++ application (in this case, the gcd implementation) to create an extension module. </p> <p> @@ -811,7 +819,7 @@ In the case where one wishes for the C++ side to own an object that was created <p> -This is some skeleton support for various STL containers. +Various STL library files are provided for wrapping STL containers. </p> <H3><a name="Octave_nn26"></a>27.3.17 Matrix typemaps</H3> diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index 16adddcce..db9592ad6 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -760,6 +760,7 @@ public: SwigType *type = Getattr(n, "type"); String *rawval = Getattr(n, "rawval"); String *value = rawval ? rawval : Getattr(n, "value"); + String *cppvalue = Getattr(n, "cppvalue"); String *tm; if (!addSymbol(iname, n)) @@ -775,7 +776,7 @@ public: if ((tm = Swig_typemap_lookup("constcode", n, name, 0))) { Replaceall(tm, "$source", value); Replaceall(tm, "$target", name); - Replaceall(tm, "$value", value); + Replaceall(tm, "$value", cppvalue ? cppvalue : value); Replaceall(tm, "$nsname", iname); Printf(f_init, "%s\n", tm); } else { diff --git a/Source/Modules/typepass.cxx b/Source/Modules/typepass.cxx index a975e350c..e63b58a10 100644 --- a/Source/Modules/typepass.cxx +++ b/Source/Modules/typepass.cxx @@ -807,11 +807,15 @@ class TypePass:private Dispatcher { value = name; if (Strcmp(value, name) == 0) { String *new_value; - if (((nsname) || (inclass)) && cparse_cplusplus) { + if ((nsname || inclass) && cparse_cplusplus) { new_value = NewStringf("%s::%s", SwigType_namestr(Swig_symbol_qualified(n)), value); } else { new_value = NewString(value); } + if ((nsname || inclass) && !cparse_cplusplus) { + String *cppvalue = NewStringf("%s::%s", SwigType_namestr(Swig_symbol_qualified(n)), value); + Setattr(n, "cppvalue", cppvalue); /* for target languages that always generate C++ code even when wrapping C code */ + } Setattr(n, "value", new_value); Delete(new_value); } |