javascript ctypes字符串到unsigned char

时间:2013-06-05 14:18:54

标签: javascript c firefox firefox-addon jsctypes

我有一个共享的C库,期望unsigned char *作为参数之一

将Javascript字符串作为unsigned char *的最佳方法是什么?

在我的js文件中,我将参数声明为ctypes.unsigned_char.ptr,但它不会只是将javascript字符串作为参数传递

这一切都是在firefox扩展的上下文中完成的。这是我对函数的声明

var myfunction = mylib.declare("function",
                           ctypes.default_abi,
                           ctypes.int,
                           ctypes.unsigned_char.ptr,
                           ctypes.long);

其中mylib是var i,它使用ctypes模块加载了共享库。

1 个答案:

答案 0 :(得分:1)

以下should work

  • 将参数声明为ctypes.uint8_t
  • 将参数传递为ctypes.uint8_t.ptr(new Uint8Array(...))