swig

How to access variables of the class that runs the Lua script from Lua

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-13 00:23:05
问题 I wonder if it's possible to access the variables of the class that runs the Lua script from the bound C++ class that is being used in Lua script. From the example below, I wonder if it's possible to access name variable in myLua class from the bound Test class somehow. Here are my codes. main.cpp : extern "C" { int luaopen_my(lua_State* L); } class myLua { public: struct myData { std::string name; lua_State *L; }; myLua(std::string name) { data = make_shared<myData>(); data->name = name;

UnsatisfiedLinkError: The library loads but I still get a link error

情到浓时终转凉″ 提交于 2019-12-13 00:15:03
问题 I have two Eclipse plugins: plugin-1: provides a package in .jar to other plugins. (a Java Wrapper for a C++ library) This plugin was created by clicking File->New->Other->Plug-in from Existing JAR Archives. plugin-2: has the native library .so for plugin-1 ( Bundle-NativeCode directive is in MANIFEST.MF) and instantiates a class from plugin-1 (I actually tried putting the .so in plugin-1, but I cannot seem to load the library, even with the Bundle-NativeCode directive in the plugin-1

SWIG: Wrapping C API in OO way

久未见 提交于 2019-12-12 23:15:29
问题 I have a C (not C++) library that consistently uses the first parameter of functions as context object (let's call the type t_context ), and I'd like to use SWIG to generate C# wrappers keep this style of call (i.e. instead of the functions being more or less isolated, wrap them as methods in some class and access the t_context via a reference from the this object within the methods). Example (C signature): void my_lib_function(t_context *ctx, int some_param); Desired C# API: class Context {

SWIG argument error when using “using std::vector” in python

佐手、 提交于 2019-12-12 21:19:31
问题 This is very related to this question Regardless of whether or not this is coding practice, I have come across code that looks like this test.hh #include <vector> using std::vector; class Test { public: vector<double> data; }; I am trying to swig this using swig3.0 using the following interface file test.i %module test_swig %include "std_vector.i" namespace std { %template(VectorDouble) vector<double>; }; %{ #include "test.hh" %} %naturalvar Test::data; %include "test.hh" And the following

Python callback with SWIG wrapped type

被刻印的时光 ゝ 提交于 2019-12-12 21:11:53
问题 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 hasn't gone through swig, and isn't a PyObject. I tried using: swigData = SWIG_NewPointerObj((void*)data, NULL, 0); But because its a template, I don't really know what to use for the second parameter. Even if I do hard code

Wrapping a void * argument in Python SWIG

老子叫甜甜 提交于 2019-12-12 20:42:59
问题 I am wrapping this lib with Python SWIG that has a function looking like this: int set_option(Foo *foo, const char *name, void *value); In the lib const char *name is mapped to a type that I have access to look up: int , char * , char ** . The wrapper code generated by default accepts only a wrapped void * (naturally). What is the best way to make the wrapped method accept any Python object as argument, and do the type checking, and Python to C conversion in my own C code? My guess would be

SWIG Python fixed size array passed by reference

[亡魂溺海] 提交于 2019-12-12 19:31:56
问题 I have been trying to figure out how to pass a fixed size array by reference using SWIG to python. Mostly I have been considering the numpy.i interface for this. However, I can't seem to find any reference to this online. For regular array passing to numpy the way you do is it first the C++ function in foo.h : void foo(double* array, int length); And the relevant part of the SWIG file is: %include "numpy.i" %init %{ import_array(); %} %apply (unsigned char* IN_ARRAY1, int DIM1) {(unsigned

SWIG call function pointers stored within struct

丶灬走出姿态 提交于 2019-12-12 17:40:58
问题 I have a struct as follows: struct power_model { int64_t (*estimate_energy)(statistics *stats, statistics *scaled_stats, parameters *from, parameters *to, energy_container *energy_container); int64_t (*estimate_performance)(statistics *stats, parameters *params); uint32_t (*freq_to_volt)(uint32_t freq); }; There are multiple power models that my code contains. I would like to wrap these models with SWIG and expose them to Python so that I can run my unit tests. While the SWIG documentation

With SWIG, how do you wrap C++ void func(Class& out) as C# Class func()?

爷,独闯天下 提交于 2019-12-12 16:20:07
问题 (Unfortunately, SWIG's documentation is very difficult to parse and online examples seem rare. So I come here.) Suppose a C++ function uses this typical return style for a class type: void func(Class& out); Using SWIG, this function should be wrapped in C# like this: Class func(); From what I've found, I can use a typemap to accomplish this. Pretending that Class is actually int , I've attempted the following based on examples I've found: %include <typemaps.i> %{ void func(int& pOut); %}

How to wrap UTF-8 encoded C++ std::strings with Swig in C#?

安稳与你 提交于 2019-12-12 14:27:47
问题 My question is nearly identical to this question, except that the linked question deals with char*, whereas I'm using std::string in my code. Like the linked question, I'm also using C# as my target language. I have a class written in C++: class MyClass { public: const std::string get_value() const; // returns utf8-string void set_value(const std::string &value); // sets utf8-string private: // ... }; And this get's wrapped by SWIG in C# as follows: public class MyClass { public string get