зеркало из https://github.com/mozilla/chromeless.git
working example of how to use jsctypes to include native code in a module
This commit is contained in:
Родитель
ce1e371ea7
Коммит
2f9a7211e2
|
@ -0,0 +1,5 @@
|
|||
const char * gettaStringFromNativeCode(void)
|
||||
{
|
||||
return "This string has come a loooong way";
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
const {Cc,Ci,Cm,Cr,Cu} = require("chrome");
|
||||
|
||||
const path = require("path");
|
||||
|
||||
/* Load JS Ctypes Javascript module */
|
||||
ctypes = {};
|
||||
Cu.import("resource://gre/modules/ctypes.jsm", ctypes);
|
||||
ctypes = ctypes.ctypes;
|
||||
|
||||
exports.getString = function() {
|
||||
let pathToLib = require("url").toFilename(__url__);
|
||||
pathToLib = path.join(path.dirname(pathToLib), 'libmylib.dylib');
|
||||
let lib = ctypes.open(pathToLib);
|
||||
let getStr = lib.declare("gettaStringFromNativeCode",
|
||||
ctypes.default_abi,
|
||||
ctypes.char.ptr);
|
||||
let rv = getStr().readString();
|
||||
lib.close();
|
||||
return rv;
|
||||
};
|
|
@ -0,0 +1,4 @@
|
|||
<script>
|
||||
const mylib = require('jsctypes/mylib');
|
||||
console.log(mylib.getString());
|
||||
</script>
|
Загрузка…
Ссылка в новой задаче