swig

How should I unit test a code-generator?

This is a difficult and open-ended question I know, but I thought I'd throw it to the floor and see if anyone had any interesting suggestions. I have developed a code-generator that takes our python interface to our C++ code (generated via SWIG) and generates code needed to expose this as WebServices. When I developed this code I did i...

Prototyping hybrid Python code

I have been mulling over writing a peak fitting library for a while. I know Python fairly well and plan on implementing everything in Python to begin with but envisage that I may have to re-implement some core routines in a compiled language eventually. IIRC, one of Python's original remits was as a prototyping language, however Python ...

What are the best practices when using SWIG with C#?

Has anybody out there used the SWIG library with C#? If you have, what pitfalls did you find and what is the best way to use the library? I am thinking about using it as a wrapper for a program that was written in C and I want to wrap the header files where I can use them in my .NET application. Edit: Some clarification on target OS'...

Python: SWIG vs ctypes

In python, under what circumstances is SWIG a better choice than ctypes for calling entry points in shared libraries? Let's assume you don't already have the SWIG interface file(s). What are the performance metrics of the two? ...

Crash when calling into C++ library from Perl using SWIG (AIX 5.1)

I'm trying to call into a C++ library from Perl on an AIX 5.1 machine. I've created a very simple test project to try to exercise this. My C++ shared library (test.cpp): #include <stdio.h> #include <iostream> void myfunc() { printf("in myfunc()\n"); std::cout << "in myfunc() also" << std::endl; } My SWIG interface file (tes...

load dll from python

Hello. I'm building a python application from some source code I've found Here I've managed to compile and fix some problems by searching the web, but I'm stuck at this point: When running the application this message appears. This python app, usues swig to link to c/c++ code. I have VC++2005 express edition which I used to compi...

Referencing existing SWIG wrappers when creating new ones

I have an existing library (JPhysX) that is a Java wrapper for a native C++ library (PhysX). The Java library makes use of types generated by SWIG, for example, com.jphysx.SWIGTYPE_p_NxStream, which represents a pointer to an NxStream object in the C++ code. Now I want to create my own C++ class that inherits from the C++ type NxStream, ...

Exposing a C++ API to Python

I'm currently working on a project were I had to wrap the C++ classes with Python to be able to script the program. So my specific experience also involved embedding the Python interpreter in our program. The alternatives I tried were: Boost.Python I liked the cleaner API produced by Boost.Python, but the fact that it would have requ...

How to expose std::vector<int> as a Python list using SWIG?

I'm trying to expose this function to Python using SWIG: std::vector<int> get_match_stats(); And I want SWIG to generate wrapping code for Python so I can see it as a list of integers. Adding this to the .i file: %include "typemaps.i" %include "std_vector.i" namespace std { %template(IntVector) vector<int>; } I'm running SWIG ...

Wrapping boost::signal to C# delegates

Hi, say I have an asynchronous library, written in native C++, with an interface similar to this: class connection { public: boost::signal< void() > sig_connection_made; boost::signal< void(const std::string&) > sig_error; void connect(const std::string& host, const std::string& port); }; that I want to wrap in C#. Does ...

Passing a Python array to a C++ vector using Swig

I have an array of objects in Python [obj1, obj2, obj3] and I want to pass them to off to a C++ function to perform some computation. I'm using SWIG to write my interface. The class type of the passed object is already defined in C++. What's the best way to do this? ...

SWIG for making PHP extensions, have you tried it?

I have a few small libraries and wrappers written in C (not C++) that I would like to make available to PHP via extensions. I read several tutorials on writing proper PHP extensions and it does not seem to difficult, however I don't want the hassle of maintaining the extensions in addition to the libraries. I read that SWIG supports bui...

Extending python - to swig or not to swig

I found the bottleneck in my python code, played around with psycho etc. Then decided to write a c/c++ extension for performance. With the help of swig you almost don't need to care about arguments etc. Everything works fine. Now my question: swig creates a quite large py-file which does a lot of 'checkings' and 'PySwigObject' before c...

Missing symbol after compiling swig interface

Hi, Im trying to compile a php interface for my linux shared object and i have managed to get it to compile all right using the output from swig, however when i try and load the so it complains of a missing symbol: error: undefined symbol: zend_register_long_constant Now i have had a look at zend and it seems to be a php framework. I...

How to use swig to generate php interface for c++ so

Ok, I have tried a 100 things and i can not get my so file to interface with php using swig. I can generate the files, then i had to compile zend and link with that to make the so but it keeps seg faulting on load now. Can some one please walk me though how to use swig to generate a php interface for a c++ so as the one on there site i...

C to Python via SWIG: can't get void** parameters to hold their value

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 Operation() alloca...

Polymorphism across C++ and Ruby using SWIG

I use SWIG to wrap a Ruby script around a C++ library. In Ruby, I can inherit from a C++ class, but I cannot pass the resulting pointer to a C++ function in a polymorphic way. Here is a concrete example. The SWIG interface file defines base class Animal with virtual function sound(): [animals.i] %module(directors="1") animals %{ #i...

How to embed lua in c++ via SWIG

Currently I have a set of SWIG wrappers for my classes and it all builds. I can create a lua virtual machine and load my wrappers, but at that point I'm flummoxed. Googling tells me how to shove put c++ in lua in swig, but not how to put lua in c++. Really all I want to do is manage to instantiate a lua object and pass it my main game e...

SWIG Lua and passing arrays

I currently have the following lua code: g = engine.CGeometry() vertexes = {} vertexes[1] = 0 vertexes[2] = 0 vertexes[3] = 0 vertexes[4] = 0 vertexes[5] = -1 vertexes[6] = 0 vertexes[7] = -1 vertexes[8] = 0 vertexes[9] = 0 print "adding vertexes" g:SetVertexes(vertexes) where g...

How do I push An instance of a c++ class wrapped with swig onto a lua stack?

I have a class that is wrapped with swig, and registered with lua. I can create an instance of this class in a lua script, and it all works fine. But say I have an instance of a class made in my c++ code with a call to new X, and I have la lua_state L with a function in it that I want to call, which accepts one argument, an instance of ...