swig

How to check Lua version in SWIG interface file?

假如想象 提交于 2019-12-24 08:48:29
问题 I have the below function which I would like to use only when the Lua version is equal to, or smaller than 5.1 . So I wrote it like the following in myBindings.i file: /* used to backport lua_len to Lua 5.1 */ #if LUA_VERSION_NUM <= 501 %{ static void lua_len(lua_State *L, int i) { switch (lua_type(L, i)) { case LUA_TSTRING: lua_pushnumber(L, (lua_Number)lua_objlen(L, i)); break; case LUA_TTABLE: if (!luaL_callmeta(L, i, "__len")) lua_pushnumber(L, (lua_Number)lua_objlen(L, i)); break; case

SWIG typemap uint8_t* from C/C++ to java.nio.ByteBuffer

别等时光非礼了梦想. 提交于 2019-12-24 08:39:46
问题 I'm trying to pass an input and an output buffer to a java class from C++. For efficiency reasons, I need to use a ByteBuffer. Both of the buffers were allocated in the C++ part and I need to pass them to a java function that will use the input buffer for some computation and write the result into the output buffer. Here is an simplified example of how the C++ looks like: // SWIG mapped with %feature("director") JavaDelegate; class JavaDelegate { public: JavaDelegate() {} virtual

hexo+NexT博客最新定制记录

大兔子大兔子 提交于 2019-12-24 01:10:10
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 最近对hexo和NexT博客又做了一次定制。 1 增加clustrmaps 这回在博客里增加一个clustrmaps的地球点击效果,之前尝试了下,失败了,这回成功显示了。这个功能需要先在这个 网页 注册。效果如图: 后面只需要把对应的代码添加到文件中。有人推荐放到这个路径下:themes\next\layout_partials\footer.swig。这个是放在底部的,最后我是放在了侧边栏下。侧边栏的路径为themes\next\layout_custom\sidebar.swig。也有人放在themes\next\layout_partials\header.swig。但这个路径不适合我目前这个NexT的样式。 2 视频播放 增加了一个视频播放的功能,首先先安装dplayer。 npm install hexo-tag-dplayer --save 然后使用方法如下,给一个样例。详细文档参见 官方地址 {% dplayer key=value ... %} 这里展示一个上海陆家嘴变化的视频。 {% dplayer "url= http://blog.gisersqdai.top/shanghaiurbandevlopment.mp4 " "api= https://api.prprpr.me/dplayer

IDA Python - Why My code return incorrect ESP Value?

蓝咒 提交于 2019-12-24 00:54:20
问题 I made a ida python code which for checking code coverage. But when I used this script, I got a runtime error and I could not get correct ESP value. -My code- from idaapi import * class DbgHook(DBG_Hooks): def dbg_process_exit(self, pid, tid, ea, code): # bpt Del for fun in Functions(SegStart(ScreenEA()),SegEnd(ScreenEA())): DelBpt(fun) return debugger.unhook() def dbg_bpt(self, tid, ea): RefCode = get_long(GetRegValue('esp')) print "[*] Hit : 0x%08x - %s" % (ea , GetFunctionName(ea)) print "

Creating a C++ function that calls other Lua function

拥有回忆 提交于 2019-12-23 23:28:24
问题 I wonder if it's possible to create a C++ function that takes Lua function as argument to call it. For example in Lua, function sub() print('I am sub function') end function main() callfunc(sub) //C++ function that takes a function variable to call end Is it possible to create callfunc() function in C++? I'm using SWIG by the way. 回答1: You can create a callback by passing the Lua interpreter state down to the C++ function using the special lua_fnptr.i header. The header file also contains

double to PyFloat conversion is incorrect

房东的猫 提交于 2019-12-23 22:14:03
问题 I'm learning SWIG, for using C in Python. I've written this function, but I can't understand, why the wrapped myfunc returns wrong float/double values: mfuncs.c #include <stdlib.h> float myfunc(int n) { float result; result = 100 / n; return result; } mfuncs.i %module mfuncs %typemap(out) double, float "$result = PyFloat_FromDouble($1);" extern float myfunc(int n); Finally I get 1107558400.0 instead of 33.33333. >>> import mfuncs >>> mfuncs.myfunc(3) 1107558400.0 >>> Where is the mistake? 回答1

return double * from swig as python list

╄→гoц情女王★ 提交于 2019-12-23 22:06:41
问题 I have a C++ class, one of whose methods returns a double * array-like that is one of its member variables. I'm trying to make this accessible as a list in Python. I wrap it in a doubleArray_frompointer , and then try using deepcopy to get it out of there safely, but I still have problems when the doubleArray goes out of scope, its memory is cleaned up, and then the C++ class tries to clean up the same memory (although that's not shown in the gist I created). I suspect I should be doing this

Force SWIG generated Lua wrapper to allow extra arguments for varargs functions

谁说我不能喝 提交于 2019-12-23 21:18:51
问题 When I generate a wrapper of a varargs function with SWIG it inserts code that checks the exact number of arguments passed to the function, for example given: %inline %{ void foobar(const char *fmt, ...) {} The generated wrapper always inserts: SWIG_check_num_args("foobar",1,1) How can I work around that and allow any number of arguments larger or equal to 1? 回答1: It is possible to work around this and generate code that won't error when passed extra arguments using a series of hacks.

Can I use generated swig code to convert C++ object to PyObject?

放肆的年华 提交于 2019-12-23 18:32:48
问题 I'm working on embedding python into my C++ program using swig. At the moment I have a object written in C++ which I want to pass to a python function. I've created the swig interface to wrap the class. What I'm trying to do is take this C++ object which I've created and pass it to a python function with the ability to use it like I would in C++. Is it possible for me to use code generate by swig to do this? If not how can I approach this? 回答1: You can use PyObject_CallMethod to pass a newly

SWIG: Warning 453: Can't apply (char *STRING,size_t LENGTH). No typemaps are defined

核能气质少年 提交于 2019-12-23 18:17:53
问题 I have a very small .i file basically with this information: %module (directors="1") tu %include "typemaps.i" %include "enums.swg" %header %{ #include <my_header.h> %} %apply (char *STRING, size_t LENGTH) { (char* msg_buf, int buf_len) }; When generating java bindings there are no warnings but when generating c# bindings I get this: SWIG: Warning 453: Can't apply (char *STRING,size_t LENGTH). No typemaps are defined Can anyone advise on what might be the problem. The .i file is identical for