swig

Callback from C++ to C# using SWIG

霸气de小男生 提交于 2021-02-20 19:23:31
问题 I have an application running in C#.Netcore and C++ windows application. I achieved interoperability between C# & C++ using SWIG. But I am not able to achieve Callback functionality from C++ to C#. Also I tried by passing function pointer from C# to C++. But it also failed My Intention is to achieve callback by By passing a C# function pointer to C++ and call that function pointer when needed so that C# function will be executed. Creating a base class with virtual function in C++ and derive a

Callback from C++ to C# using SWIG

喜你入骨 提交于 2021-02-20 19:22:11
问题 I have an application running in C#.Netcore and C++ windows application. I achieved interoperability between C# & C++ using SWIG. But I am not able to achieve Callback functionality from C++ to C#. Also I tried by passing function pointer from C# to C++. But it also failed My Intention is to achieve callback by By passing a C# function pointer to C++ and call that function pointer when needed so that C# function will be executed. Creating a base class with virtual function in C++ and derive a

How to use Swig to treat a void * function parameter as Python string

自闭症网瘾萝莉.ら 提交于 2021-02-19 09:05:22
问题 Here is my c++ code: struct Impl { DT* data_ptr_; Impl(void* data_ptr) : data_ptr_((DT*)data_ptr) { //do something to decipher data } }; Impl class takes a void pointer, as a input parameter. What I want to do is just pass a Python string(binary string as in Python 2.x) as parameter: data = "I'm a stirng data!" impl = Impl(data) But Swig generated module raises this TypeError: in method 'new_Impl', argument 1 of type 'void *' I'm new to swig and have searched in SWIG documentation for a whole

How to use Swig to treat a void * function parameter as Python string

戏子无情 提交于 2021-02-19 09:04:57
问题 Here is my c++ code: struct Impl { DT* data_ptr_; Impl(void* data_ptr) : data_ptr_((DT*)data_ptr) { //do something to decipher data } }; Impl class takes a void pointer, as a input parameter. What I want to do is just pass a Python string(binary string as in Python 2.x) as parameter: data = "I'm a stirng data!" impl = Impl(data) But Swig generated module raises this TypeError: in method 'new_Impl', argument 1 of type 'void *' I'm new to swig and have searched in SWIG documentation for a whole

How to use Swig to treat a void * function parameter as Python string

风流意气都作罢 提交于 2021-02-19 09:04:01
问题 Here is my c++ code: struct Impl { DT* data_ptr_; Impl(void* data_ptr) : data_ptr_((DT*)data_ptr) { //do something to decipher data } }; Impl class takes a void pointer, as a input parameter. What I want to do is just pass a Python string(binary string as in Python 2.x) as parameter: data = "I'm a stirng data!" impl = Impl(data) But Swig generated module raises this TypeError: in method 'new_Impl', argument 1 of type 'void *' I'm new to swig and have searched in SWIG documentation for a whole

swig: How to make a QList<T> iterable, like std::vector

拈花ヽ惹草 提交于 2021-02-19 02:39:10
问题 I'm using SWIG to generate Python Bindings for my qt app. I have several places where I use QLists and I would like to integrate those QLists like std::vector from the SWIG Library (see http://www.swig.org/Doc1.3/Library.html#Library_nn15). This means: The QList objects should be iterable from python (= they must be an iterable python object) It should be possible to pass a python list to a function which takes a qlist ... and all the other features listed in the SWIG Library for std::vector

Rust FFI 编程

谁说我不能喝 提交于 2021-02-15 13:33:49
FFI(Foreign Function Interface)是这样一种机制:用一种编程语言写的程序能调用另一种编程语言写的函数(routines)。 FFI 有两种内涵。一种是是在当前正在使用的语言(host)中,调用由其它语言(guest)提供的库。第二种内涵与第一种方向相反,即,使用当前语言(host)写库,供其它语言(guest)调用。不过,后者不是任何语言都能做到的,有些语言即使能做,也会非常吃力。 FFI 的历史和现状 FFI 这个术语最早来自 Common Lisp 的规范[1]。目前几乎所有严肃编程的语言都有提供 FFI 的支持,但大多数是单向功能。 不同语言称呼这种语言间调用的功能名字可能不同。Common Lisp、Haskell、Python、Rust 这些叫 FFI,Java 叫 JNI 或 JNA,还有一些其它语言叫 “绑定”。严格来说,FFI 与 绑定,意义并不相同,绑定可以理解为 FFI 中的一种实现。 不同语言实现 FFI 的方式不尽相同。有的语言,比如,要调用 C 库,必须用 C 语言,按那种语言的绑定规范,实现一个 C 项目,用 C 编译器编译并链接,生成库文件,再由这种语言调用(这种语言本身已经实现了加载其定义的规范 C 库的能力)。 有的语言,比如,Rust,要调用 C 库,不再需要使用 C 语言写绑定工程,而是直接使用 Rust 语言写

why swig casts python list to std::vector seamlessly and not std::set?

情到浓时终转凉″ 提交于 2021-02-11 14:47:11
问题 I make some trials with swig in order to extend basic C++ class to python. I found a behavior related to the use of sets that I can't explain so far. Here are my scripts: MyClass.h: #pragma once #include <set> #include <vector> class MyClass { public: MyClass(); void setSTLVector(const std::vector<int> &vector); void setSTLSet(const std::set<int> &set); private: std::vector<int> _stlVector; std::set<int> _stlSet; }; MyClass.cpp: #include "MyClass.h" MyClass::MyClass() { } void MyClass:

tuple is returned by python wrapper generated by swig for a C++ vector

眉间皱痕 提交于 2021-02-11 12:56:58
问题 For the following C++ API: std::vector<float> get_sweep_points() { return program->sweep_points; } Swig generates a wrapper which returns a tuple () , rather than a list [] . Why? How can I force Swig to return a list to python. 回答1: If you use std_vector.i , you get typemaps as implemented by std_vector.i . If you don't like it, you have to write your own typemaps. Here's a typemap to override the default behavior (no error checking) and return a list instead of a tuple: %typemap(out) std:

Swig Perl: wrong ELF class

孤者浪人 提交于 2021-02-11 12:36:31
问题 I am trying to build a Perl module out of a CXX module using Swig. There are multiple guides related to this: The generic Swig tutorial with a Perl section The Swig and C++ guide The Swig and Perl5 guide I'm new to Swig and not very familiar with C(++), but I've been able to compile my module following the tutorial in 1: I created an interface file: %module my_module %{ #include "case.h" #include "case.h" #include "lexindex.h" #include "intlist.h" #include "weight.h" #include "invindex.h"