typemaps

Simpler way to create a SWIG typemap for a function with multiple arguments?

雨燕双飞 提交于 2020-01-24 01:34:05
问题 Here's the C++ function that I want to wrap using SWIG. static void my_func(t_string name, t_string value) { do_something(name, value); } And here are the SWIG typemaps. %typemap(in) (t_string name) { if (!lua_isstring(L, $input)) { SWIG_exception(SWIG_RuntimeError, "argument mismatch: string expected"); } $1 = lua_tostring(L, $input); } %typemap(in) (t_string value) { if (!lua_isstring(L, $input)) { SWIG_exception(SWIG_RuntimeError, "argument mismatch: string expected"); } $1 = lua_tostring

how to pass enum values from TCL script to C++ class using Swig

我的梦境 提交于 2019-12-04 05:36:26
问题 I am using following code 1) File : example.i %module example %{ /* Put header files here or function declarations like below */ #include "example.h" %} %include "example.h" 2) File example.h enum Type {one,two}; class myClass { public: myClass() {} static bool printVal(int val); static bool printEnum(Type val); }; 3) File example.cpp #include "example.h" #include <iostream> using namespace std; bool myClass::printVal(int val) { cout << " Int Val = " << val << endl; return 0; } bool myClass:

Proper way to free a pointer array in SWIG input typemap?

我的梦境 提交于 2019-12-02 14:06:56
问题 Hi I'm trying to wrap the following function using SWIG. static void readTable(int argc, t_atom *argv) { //accepts table in Lua e.g. readTable({"ab",3}); for (int i=0; i<argc; ++i) { if (argv[i].a_type == A_FLOAT) printf("FLOAT : %g\n", argv[i].a_w.w_float); else if (argv[i].a_type == A_SYMBOL) printf("SYMBOL : %s\n", argv[i].a_w.w_symbol->s_name); } } Here's the typemap I created. %include "exception.i" %typemap(in) (int argc, t_atom *argv) { if (!lua_istable(L, 1)) { SWIG_exception(SWIG

how to pass enum values from TCL script to C++ class using Swig

梦想与她 提交于 2019-12-02 11:50:18
I am using following code 1) File : example.i %module example %{ /* Put header files here or function declarations like below */ #include "example.h" %} %include "example.h" 2) File example.h enum Type {one,two}; class myClass { public: myClass() {} static bool printVal(int val); static bool printEnum(Type val); }; 3) File example.cpp #include "example.h" #include <iostream> using namespace std; bool myClass::printVal(int val) { cout << " Int Val = " << val << endl; return 0; } bool myClass::printEnum(type val) { cout << " Enum Val = " << val << endl; return 0; } Steps to compile and run swig

Proper way to free a pointer array in SWIG input typemap?

偶尔善良 提交于 2019-12-02 03:19:37
Hi I'm trying to wrap the following function using SWIG. static void readTable(int argc, t_atom *argv) { //accepts table in Lua e.g. readTable({"ab",3}); for (int i=0; i<argc; ++i) { if (argv[i].a_type == A_FLOAT) printf("FLOAT : %g\n", argv[i].a_w.w_float); else if (argv[i].a_type == A_SYMBOL) printf("SYMBOL : %s\n", argv[i].a_w.w_symbol->s_name); } } Here's the typemap I created. %include "exception.i" %typemap(in) (int argc, t_atom *argv) { if (!lua_istable(L, 1)) { SWIG_exception(SWIG_RuntimeError, "argument mismatch: table expected"); } lua_len(L, 1); $1 = lua_tointeger(L, -1); $2 = (t