Link to binary component on js-ctypes

I registered the binary component in my chrome.manifest :

 binary-component components/linux/myLib.so abi=Linux_x86-gcc3 

Now I want to pass my path to ctypes.open() . My question is: how do I bind a binary component to pass it to ctypes.open() ?

+4
source share
2 answers

The binary components listed in chrome.manifest must be XPCOM components. On the other hand, yours is an ordinary library, there is no need to list it in the manifest - instead it is a very "manual" approach. Your code should check nsIXULRuntime.XPCOMABI (see https://developer.mozilla.org/En/NsIXULRuntime ) to find out if the platform is compatible. Then you need to get your library file location something like this:

 Components.utils.import("resource://gre/modules/AddonManager.jsm"); AddonManager.getAddonByID(" myAddon@foo.com ", function(addon) { var uri = addon.getResourceURI("components/linux/myLib.so"); if (uri instanceof Components.interfaces.nsIFileURL) { ctypes.open(uri.file.path); ... } }); 

The first parameter getAddonByID () should be replaced with the identifier of your add-on, of course. It is assumed that your add-on is installed without unpacking ( <em:unpack>true</em:unpack> specified in install.rdf), because otherwise the file will not be downloaded on disk.

+6
source

You can use "resource" to link to a regular binary in your addon: add this to your manifest:

 resource YOUR-ADDON-LIB path/to/libaddon.so ABI=Linux_x86-gcc3 resource YOUR-ADDON-LIB path/to/addon.dll ABI=WINNT_x86-msvc 

The "ABI" directive will provide you with the correct lib path on another platform.

In your javascript file, you can reference the lib path as follows:

 const ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); var uri = ioService.newURI('resource://YOUR-ADDON-LIB', null, null); if (uri instanceof Components.interfaces.nsIFileURL) { var lib = ctypes.open(uri.file.path); /// ... } 
+5
source

All Articles