Все вопросы: [swig]

65 вопросов

похожие теги: quantlib-swigswig-template
3
голосов
2ответов
3491 просмотров

Using SWIG with pointer to function in C struct

I'm trying to write a SWIG wrapper for a C library that uses pointers to functions in its structs. I can't figure out how to handle structs that contain function pointers. A simplified example follows. test.i: /* test.i */ %module test %{ typedef struct { int (*my_func)(int); } test_str...

7
голосов
3ответов
3010 просмотров

Releasing Python GIL while in C++ code

I've got a library written in C++ which I wrap using SWIG and use in python. Generally there is one class with few methods. The problem is that calling these methods may be time consuming - they may hang my application (GIL is not released when calling these methods). So my question is: What is...

1
голосов
2ответов
1095 просмотров

Embedding Ruby in a C++ application using SWIG?

I've successfully created Ruby-C++ bindings in the past using SWIG where the C++ code was compiled as a dynamic library with the Ruby script connecting to it. However, I'd like to do it the other way around. Create an executable using C++ and enable it to load and execute Ruby code. Ruby should ...

2
голосов
2ответов
2179 просмотров

Python callback with SWIG wrapped type

I'm trying to add a python callback to a C++ library as illustrated: template<typename T> void doCallback(shared_ptr<T> data) { PyObject* pyfunc; //I have this already PyObject* args = Py_BuildValue("(O)", data); PyEval_CallObject(pyfunc,args); } This fails because data ha...

4
голосов
3ответов
3507 просмотров

SWIG pointers and Java arrays

The SWIG documentation explains how a variety of input types in C, like this: void spam1(Foo *x); // Pass by pointer void spam2(Foo &x); // Pass by reference void spam3(Foo x); // Pass by value void spam4(Foo x[]); // Array of objects ... would all take a single type of...

1
голосов
2ответов
998 просмотров

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 SWIG...

2
голосов
1ответов
1277 просмотров

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 accompl...

2
голосов
2ответов
481 просмотров

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...

2
голосов
2ответов
2640 просмотров

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(doub...

8
голосов
1ответов
11138 просмотров

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.

0
голосов
2ответов
191 просмотров

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?

0
голосов
2ответов
941 просмотров

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: $myLis...

33
голосов
6ответов
9788 просмотров

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 ex...

1
голосов
2ответов
893 просмотров

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

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...

1
голосов
2ответов
977 просмотров

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 Consume these managed implementations from (unmanaged) C++ Using SWIG or some C++/CLI glue?

4
голосов
1ответов
2390 просмотров

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...

1
голосов
1ответов
4814 просмотров

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 ...

1
голосов
2ответов
1187 просмотров

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 (...

3
голосов
5ответов
1536 просмотров

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; ...

2
голосов
2ответов
2159 просмотров

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 ...

2
голосов
1ответов
1988 просмотров

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>::iter...

20
голосов
6ответов
8007 просмотров

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 tri...

1
голосов
1ответов
752 просмотров

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 mai...

6
голосов
1ответов
9565 просмотров

How can I read the window title with JNI or JNA?

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 m...

3
голосов
1ответов
671 просмотров

Python Hangs When Importing Swig Generated Wrapper

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...

5
голосов
2ответов
8694 просмотров

How to diagnose Java JNI EXCEPTION_ACCESS_VIOLATION errors in Windows Vista

We have a Java application that uses some C++ libraries through JNI. The application used to work just fine in Windows XP, but it does not work in Windows Vista, it just crashes the JVM right away. We also wrote the C++ libraries and produced JNI bindings using SWIG. We are a little bit clueles...

6
голосов
1ответов
1556 просмотров

Привязки Lua к C ++ и сборка мусора

Хорошо, у меня проблема. У меня есть привязки Lua к механизму рендеринга, у которого есть внутренний менеджер рендеринга, который отслеживает указатели для сцены рендеринга и управляет ими. Проблема в том, что когда я использую его из Lua, если я не сохраняю ссылку Lua на каждый отдельный объ...

3
голосов
1ответов
3013 просмотров

Swig c ++ w / Java теряет тип в полиморфных функциях обратного вызова

Возможный дубликат: SWIG Java Retaining Class информация для объектов, отскакивающих от C ++ Вопрос : Почему мой объект типа "swigged" C ++ теряет свой тип при передаче в функцию обратного вызова Java? Настройка : Я взял пример Swig Java для выполнения обратных вызовов и доб...

1
голосов
2ответов
340 просмотров

Как мне удовлетворить ссылку на общую библиотеку стороннего производителя при создании прокладки общей библиотеки, а не исполняемого файла?

Я новый специалист по сопровождению внутренней системы Python, которая использует набор сторонних разделяемых библиотек C через прокладку разделяемых библиотек, которая создается с помощью комбинации swig и скрипта setup.py. До недавнего времени это хорошо работало. Сторонние общие библиотеки...

3
голосов
2ответов
947 просмотров

Как мне создать хеш Perl на C, используя SWIG?

Я пытаюсь создать хеш Perl из библиотеки C. Вот что у меня есть на данный момент: static void add_string_to_perl_hash ( HV *hv, char * key, char *value ) { SV *obj = sv_2mortal(newSVpv(value, 0)); hv_store(hv, (const char *)key, strlen (key), obj, 0); SvREFCNT_inc(obj); } SV * do_get_tes...