我在一个名为"pruebaChar.so“的库中有这段C代码,用于jsctype:
char * ejecutarComando(char * miComando){
return miComando;
}然后,我有另一个调用“pruebaChar.so”的代码:
function miComando(unComando) {
var {Cu} = require("chrome");
var {ctypes} = Cu.import("resource://gre/modules/ctypes.jsm", null);
var lib = ctypes.open("/home/usuario/pruebaChar.so");
var comandoLib = lib.declare("ejecutarComando",
ctypes.default_abi,
ctypes.char, // return type is correct?
ctypes.char.ptr // argument type is correct?
);
/* How do I pass the argument to function
and save the return value from function?*/
var returnString = comandoLib(unComando); // Is this correct?
return ???;
}我应该在返回类型和参数类型中放入什么值?如何将参数传递给函数并保存函数的返回值?
非常感谢:)
发布于 2014-12-21 01:56:25
尝试使用ctypes.char.ptr,而不是ctypes.char,对于字符串的第一个参数,它看起来可以工作。它也是ctypes.char.ptr。
下面是一个使用字符串作为返回值的x11 jsctype的例子:
lib.lazy_bind("gtk_window_get_title",gobject.gchar.ptr,this.GtkWindow.ptr);
这只是惰性绑定,但它会转换为:
ctypes.voidptr_t);
让data = ctypes.cast(userData,_find_data_t.ptr);让inTitle = data.contents.inTitle;让gtkWin = ctypes.cast(gtkWidget,gtk.GtkWindow.ptr);让winTitle = gtk.gtk_window_get_title(gtkWin);if (!winTitle.isNull()) { log.debug(inTitle+“= "+ winTitle);if (libc.strcmp(inTitle,winTitle) == 0) =;}}
- This looks to me like the returned is not a jsstring, as he's using `libc.strcmp` for c string comparison. so i think you would have to maybe do `winTitle.readString()` to get the string into your js. maybe not, im not sure, maybe a a `winTitle.contents` would work too.
我不是一个专业的js-ctypes,但如果你可以给我你的.so文件,告诉我一点,我可以让它工作,让你知道。
https://stackoverflow.com/questions/27440699
复制相似问题