swig

Binding with SWIG - typedef'ed types bound incorrectly

孤人 提交于 2019-12-07 15:13:34
I have swig.i file like that: %module ogr_api %{ #include "ogr_api.h" %} %inline %{ typedef void *OGRSFDriverH; %} /* OGRSFDriverRegistrar */ OGRDataSourceH OGROpen( const char *, int, OGRSFDriverH * )` and I get the following .c wrapper: ... SWIGEXPORT void * D_OGROpen(char * jarg1, int jarg2, void * jarg3) { ... That is SWIG translates OGRSFDriverH to just void*. I need to save the type name. How could I do it? Also I loss const in the first argument, but this is the next question. Flexo Assuming I've understood your question correctly you have a number of opaque "handles" that in C are

How to embed lua in c++ via SWIG

偶尔善良 提交于 2019-12-07 11:36:48
问题 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 engine object pointer, from there I can manage 回答1: Take a look at the Programming in Lua book, it has a section on the Lua C API. For calling Lua functions use

Using distutils where swig interface file is in src folder

╄→гoц情女王★ 提交于 2019-12-07 10:49:02
问题 I've got a setup.py that looks something like this: from setuptools import setup, Extension import glob sources = glob.glob('src/*.cpp') + glob.glob('src/*.i') # this is ugly, but otherwise I get the wrapper included twice sources = [source for source in sources if '_wrap' not in source] setup( name = 'engine', ext_modules = [ Extension( '_engine', sources = sources, swig_opts = ['-c++'], include_dirs = ['src'] ) ], py_modules = ['engine'] package_dir = {'' : 'src'} ) Now this works as long

Using SWIG and the Python/C API to wrap a function which returns a std::map

爱⌒轻易说出口 提交于 2019-12-07 08:42:53
问题 I want to wrap a C++ routine which returns a std::map of integers and pointers to C++ class instances. I am having trouble getting this to work with SWIG and would appreciate any help that can be offered. I've tried to boil this issue down to its essence through a simple example. The header test.h is defined as follows: /* File test.h */ #include <stdlib.h> #include <stdio.h> #include <map> class Test { private: static int n; int id; public: Test(); void printId(); }; std::map<int, Test*> get

Convert a member of structure of type signed char * to byte array in Java (byte[]) using SWIG

依然范特西╮ 提交于 2019-12-07 08:04:26
问题 I'm trying to convert a member of structure of type signed char * to byte array in Java. I've the following structure: typedef struct { signed char * content; int contentLength; } Foo; I've tried this: %typemap(jni) signed char *content [ANY] "jbyteArray" %typemap(jtype) signed char *content [ANY] "byte[]" %typemap(jstype) signed char *content [ANY] "byte[]" %typemap(javaout) signed char *content [ANY] { return $jnicall; } %typemap(memberin) int contentLength [ANY] { int length=0; $1 =

SWIG Python undefined symbol error

旧街凉风 提交于 2019-12-07 07:23:53
问题 I'm trying to create a *.so file for further use in Python using SWIG, but something isn't working. I have two files: DataGatherer.h #include <iostream> #include <stdlib.h> #include <time.h> #include "gnublin.h" #include <pthread.h> class dataGatherer { private: int threshold; int timeThreshold; int data[4096]; bool running; gnublin_spi* spiDevice; pthread_t spiThread; void *params; public: dataGatherer(void); dataGatherer(int, int); void initData(); int getThreshold(void); int* getData(void)

In SWIG compilation : In header file in interface is unable to resolve other header files.

蹲街弑〆低调 提交于 2019-12-07 06:52:10
问题 In interface File. I have included a header file.In that Header file there are many header files included but from top tree bases But in Swig is not able to recognize those Eample: main.h #include<dir/second.h> #define PAGE 1 Swig is unable to resolve that dir in the header file 回答1: Use -I<dir> on the SWIG command line to tell SWIG about include paths it doesn't know about. See SWIG 2.0 command line documentation 回答2: SWIG normally does not process #include files recursively. The reason is

Avoid 'nothing known about [parent] class…' error in swig

十年热恋 提交于 2019-12-07 06:42:14
问题 Let's say I have two classes A in header file A.h // A.h class A { public: void foo(); }; and B in header file B.h // B.h class B : public A { public: void bar() }; I want to generate a Swig wrapper for class B. The interface file looks like this. B.i %{ #include "B.h" %} %include B.h When running swig, it quits with an error message 'nothing known about A', which is clear, since B inherits from A and thus swig must know about A to generate the interface. Lets further assume there is some

How to make SWIG deal with utf8 strings in C#?

大城市里の小女人 提交于 2019-12-07 06:11:12
问题 I'm writing a portable C++ library with bindings to other languages (java, C#, python). I'm making those bindings with help of SWIG. I have a class written in C++: class MyClass { public: const char* get_value() const; // returns utf8-string void set_value(const char* value); // gets utf8-string private: // ... }; And I have something like that on C# side: public class MyClass { public string get_value(); public void set_value(string value); } SWIG does everything well, except that it doesn't

SWIG - Garbage Collection using %newobject

时光毁灭记忆、已成空白 提交于 2019-12-07 05:57:02
问题 In my C code, I have the following structure : typedef struct my_structure{ char* str1; char* str2; }MyStruct; And a function that returns a MyStruct pointer : MyStruct* foo(); Inside foo, I have allocated memory for MyStruct , str1 and str2, as follows: MyStruct* obj = malloc(sizeof(MyStruct)); obj.str1 = malloc(256); obj.str2 = malloc(256); I want to call foo from python, java, C# and PHP and I don't want to have any memory leak in this process. I am not sure if writing: %newobject foo;