I am using SWIG to access C++ code from Python. How do I elegantly wrap a function that returns values in variables passed by reference like
void set(double&a) {
a = 42.;
}
I could not find out how to do this. In the best case I'd be able to use the function in Python with Python floats:
>>> b = 2.
>>> set(b)
>>> print b
42.0
At ...
Hello,
I am really new to SWIG. I tried to compile the example given in SWIG but I get the following error:
$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import example
Traceback (most recent call last):
...
I'm wrapping a C++ library in PHP using SWIG and there have been some occasions where I want to modify the generated code (both generated C++ and PHP):
Fix code-generation errors
Add code that makes sense in PHP, but not in C++ (e.g. type checking)
Add documentation tags (e.g. phpDoc)
I'm currently automating these modifications with...
I've created a PHP extension with SWIG and everything works fine, but I'm observing some strange garbage collection behavior when chaining method calls. For example, this works:
$results = $response->results();
$row = $results->get(0)->iterator()->next();
printf('%s %s' . "\n", $row->getString(0), $row->getString(1));
But this seg fau...
I have a C interface that looks like this (simplified):
extern bool Operation(void ** ppData);
extern float GetFieldValue(void* pData);
extern void Cleanup(p);
which is used as follows:
void * p = NULL;
float theAnswer = 0.0f;
if (Operation(&p))
{
theAnswer = GetFieldValue(p);
Cleanup(p);
}
You'll note that Operatio...
I have come up with an idea for an audio project and it looks like Go is a useful language for implementing it. However, it requires the ability to apply filters to incoming audio, and Go doesn't appear to have any sort of audio processing package. I can use cgo to call C code, but every signal processing library I find uses C++ classes ...
I have a C++ module that I'm wrapping with SWIG that uses dynamic linking. Because of the way that python deals with scope of imported functions I've had to run the command dl.open(library, dl.RLTD_NOW, dl.RTLD_GLOBAL) directly after import. This is to make sure that the C++ libraries functions are available to the other libraries that i...
I have a C function I want to use in Python:
extern int convertAtoB( stateStruct *myStruct,
const double PointA[3],
double PointB[3]);
Using SWIG, I think I need to define a typemap to convert the two points (PointA the input, PointB the output) so that Python can use it. There doesn't s...
I am totally new to SWIG interfaces and how to use this with C and Perl.
It will a great help to me, if someone explains about using Perl and C with SWIG.
...
I'm having trouble getting the following simple example to work with SWIG 1.3.40 (and I also tried 1.3.31). The Foo structure comes through as a Python module as long as I don't wrap it in a namespace, but as soon as I do I get a compilation error in the generated test_wrap.c.
test.h:
#ifndef __TEST_H__
#define __TEST_H__
#define USE...
Which of the following (or other) method would you recommend for accessing a C++ shared library from Java and why?
JNI: I hear this has a number of pitfalls and is quite the undertaking?
SWIG: Apparently this makes using JNI easier, but I've heard it has some problems too?
JNA: I could write a C interface and then use JNA with it i...
I found swig can generate script wrapper for various scripting languages.
I've a 3rd party static library, a header file and a lib.
How can I use swig so that I can call functions from that library from a scripting language, say python?
Thanks
...
I am using SWIG to access C++ code from Java.
What is the easiest way to expose a std::string parameter passed by non-const reference?
I have primitives passed by reference exposed as Java arrays, thanks to typemaps.i, and const std::string&s exposed as java.lang.String, thanks to std_string.i. But a non-const std::string& is exposed a...
Hi,
I'm using SWIG to wrap C++ code to Python code.
I'm trying to wrap a vector of vectors.
The method is:
std::vector<std::vector<MyClass*>*> GetMyClassVectorOfVectors();
I'm able to wrap the first vector without adding lines to the file "MyAplication.i":
The method is
std::vector<MyClass*> GetMyClassVector();
And this is working...
I want to wrap a C++ vector of vectors to Python code by using SWIG.
Is it possible to wrap this type of vector of vectors?
std::vector<std::vector<MyClass*>>;
In the interface file MyApplication.i I added these lines:
%include "std_vector.i"
%{
#include <vector>
%}
namespace std {
%template(VectorOfStructVector) vector<vecto...
I have working C++ code using swig which creates a struct, passes it to lua (essentially by reference), and allows manipulation of the struct such that the changes made in the lua code remain once I've returned to the C++ function. This all works fine until I add a std::string to the struct, as shown here:
struct stuff
{
int x;
...
Hello, I'm new to SWIG and I'm trying to make a PHP5 wrapper around this library
https://sourceforge.net/projects/zinnia/
The project includes the interface file zinnia.i
Following www.swig.org/Doc1.3/Php.html
I run
swig -php -c++ zinnia.i
gcc `php-config --includes` -fpic -c zinnia_wrap.cpp
gcc -shared -L/usr/local/lib/ -lzinnia -o ...
We are implementing a wrapper on C++ code for exposure to Java clients. I have seen the SWIG documents about exception handling but what does this translate to in coding terms in the three layers (C++/SWIG/Java)?
If anybody has working example(s) or advice, I would be grateful.
...
I am trying to write an SCons script to build lua/embed3 example distributed with swig. Build instructions by makefile as follows:
swig -c++ -lua -external-runtime swigluarun.h
swig -c++ -lua -module example -o example_wrap.cpp example.i
g++ -o embed3 embed3.cpp example_wrap.cpp example.cpp \
-llua5.1 -I/usr/include/lua5.1
In Scon...
I am new in C# programming and trying to call wrap functions that is in C++.
In C++ I have a function of the following prototype
string* swap(string* ptr1, string*ptr2){
//swap the array of string
return ptr2;
}
How do I wrap this function into C# (ideally using SWIG, but not necessary)?
...