swig

Python Hangs When Importing Swig Generated Wrapper

Hi, Python is 'hanging' when I try to import a c++ shared library into the windows version of python 2.5 and I have no clue why. On Linux, everything works fine. We can compile all of our C++ code, generate swig wrapper classes. They compile and can be imported and used in either python 2.5 or 2.6. Now, we are trying to port the cod...

java - JNI/JNA - Get Window Title

Looking to get back into the development space; primarily using Java to call some native win32 functions (I don't desire to build in .NET).... Can someone point me to a place where I can read the title from a differnt running window using Java (JNI/JNA/SWIG). Assume you would know where in the memory space the application you are attemp...

How do I return a pointer to a user-defined class object using SWIG

I have the following code wrapped by swig: int cluster::myController(controller*& _controller) { _controller = my_controller; return 0; } controller has a private constructor. What's the correct incantation to make something like this not throw an exception? public static void main(String argv[]) { controller c = null; ...

Python Properties & Swig

I am attempting to create python bindings for some C++ code using swig. I seem have run into a problem trying to create python properties from some accessor functions I have for methods like the following: class Player { public: void entity(Entity* entity); Entity* entity() const; }; I tried creating a property using the python pr...

How do I pass Perl arrays to/from SWIG?

In Perl, I'm accustomed to passing arrays to and from subs sub abc { foreach my $x (@_) { print $x; } return (0, 1, 2); } How can I achieve similar behavior with SWIG'ed functions? SWIG'ing this: std::vector<int> print_list(std::vector<int> l) { std::vector<int>::iterator iter; for(iter=l.begin(); iter!=l.end(); iter++) { ...

SWIG OpenSSL 1.0 - Problem with STACK_OF Macros

With prior OpenSSL versions it was possible to do this in SWIG .i files: STACK *ssl_get_ciphers(SSL *ssl) { return (STACK *)SSL_get_ciphers(ssl); } With OpenSSL 1.0.0beta3 this fails because STACK seems to be no longer defined. New OpenSSL tries to do a better job at type checking, so one is supposed to use the STACK_OF macro, whi...

Swig C++ Lua Pass class by reference

I don't know why I'm having a hard time with this. All I want to do is this: class foo { public: foo(){} ~foo(){} float a,b; }; class foo2 { public: foo2(){} foo2(const foo &f){*this = f;} ~foo2(){} void operator=(const foo& f){ x = f.a; y = f.b; } float x,y; }; /* Usage(...

How can I collapse multiple arguments into one SWIG parameter

I'm trying to write a typemap that converts multiple/variable arguments into one input parameter. For example, say I have a function that takes a vector. void foo(vector<int> x); And I want to call it like this (happens to be in Perl) foo(1,2,3,4); The typemap should take arguments ($argnum, ...), gather them into one vector and t...

C++ "conversion loses qualifiers" compile error

I ran into an interesting problem while debugging SWIG typemaps today. Anyone care to enlighten me why Visual C++ 2008 throws a "conversion loses qualifiers" error when converting from ourLib::Char * to const ourLib::Char * &? I thought Type * -> const Type * was a trivial conversion, and (when calling functions) Lvalue -> Lvalue & as we...

Python non-trivial C++ Extension

I have fairly large C++ library with several sub-libraries that support it, and I need to turn the whole thing into a python extension. I'm using distutils because it needs to be cross-platform, but if there's a better tool I'm open to suggestions. Is there a way to make distutils first compile the sub-libraries, and link them in when ...

Unmanaged base class with Managed subclass

Is it possible to have: A pure abstract class (basically an interface) in (unmanaged) C++ Have managed implementations of this class in <insert .net language of your choice> Consume these managed implementations from (unmanaged) C++ Using SWIG or some C++/CLI glue? ...

How do I use a pointer to char from SWIG, in Perl?

Hi, I used SWIG to generate a Perl module for a C++ program. I have one function in the C++ code which returns a "char pointer". Now I dont know how to print or get the returned char pointer in Perl. Sample C code: char* result() { return "i want to get this in perl"; } I want to invoke this function "result" in Perl and pr...

How do I propagate C++ exceptions to Python in a SWIG wrapper library?

I'm writing a SWIG wrapper around a custom C++ library which defines its own C++ exception types. The library's exception types are richer and more specific than standard exceptions. (For example, one class represents parse errors and has a collection of line numbers.) How do I propagate those exceptions back to Python while preserving t...

How do I access List template of C++ program from Perl using SWIG?

I want to access a template List of C++ program from a Perl script and use those values. Example code: typedef list < Struct1 * > sturct1_list; struct Struct2 { int i; struct1_list List1; } struct Struct1 { int j; } I used one swig generated api and did the following: $myList = Struct2_struct1List_get print "Referenc...

How to add bindings to a new language?

So you've got to create your own scripting language built in .NET C#. What's better now for libraries? (think SDL/OPENGL), generate wrappers with Swig or do it by hand? Any other choice? ...

Generating SWIG bindings with CMake

How would I generate automatic bindings for a C project that is built using CMake? I want to generate bindings for Python, Java, .NET, PHP, Perl, TCL, Ruby and Octave automatically. ...

How do I define a SWIG typemap for a reference to pointer?

I have a Publisher class written in C++ with the following two methods: PublishField(char* name, double* address); GetFieldReference(char* name, double*& address); Python bindings for this class are being generated using SWIG. In my swig .i file I have the following: %pointer_class(double*, ptrDouble); This lets me publish a fiel...

SWIG / Lua: Determine member field data type

SWIG graciously provides the swig_type() function to get a string representation of the data type of a passed userdata object. However, in the case of member fields, SWIG and Lua consider those to be simple "number" items and so prints only "number" instead of the data type's name. e.g. typedef num_years int; class Person { public...

Using SWIG with a build system

Anyone have experience with using SWIG (the interface generator)? I have a C project which I would like to expose to a bunch of other languages/frameworks, like Python, Java, .NET, Perl, PHP, Ruby. I would like to integrate with my build system (which is CMake-based), but any method of accomplishing this will do. ...

Java and SDL_GetKeyState()

I'm trying to convert to Java some code that uses SDL. I'm using the sdljava bindings. sdljava uses SWIG as the bridge between the C datatypes and Java. To get the equivalent of SDL_GetKeyState(), sdljava provides the method SWIG_SDLEvent.SDL_GetKeyState(), which returns something called a SWIGTYPE_p_unsigned_char. Of course, Java has...