引用一个二进制组件到js-ctypes [英] Reference a binary-component to js-ctypes

查看:158
本文介绍了引用一个二进制组件到js-ctypes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 chrome.manifest 中注册了一个二进制组件:

I have registered a binary component in my chrome.manifest:

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

现在我想将其路径传递给 ctypes.open()。我的问题是:如何引用二进制组件,所以我可以将它传递给 ctypes.open()

Now I want to pass its path to ctypes.open(). My question is: how do I reference the binary component so I can pass it to ctypes.open()?

推荐答案

chrome.manifest中列出的二进制组件应该是XPCOM组件。另一方面,你是一个普通的图书馆,不需要在清单上列出 - 这是一个非常手动的方法。您的代码需要检查nsIXULRuntime.XPCOMABI(请参阅 https://developer.mozilla.org/En/NsIXULRuntime)来查看平台是否兼容。然后你需要得到你的库文件的位置,如下所示:

The binary components listed in chrome.manifest should be XPCOM components. Yours on the other hand is a regular library, no need to list it in the manifest - it is a very "manual" approach instead. Your code needs to check nsIXULRuntime.XPCOMABI (see https://developer.mozilla.org/En/NsIXULRuntime) to see whether the platform is compatible. Then you need to get the location of your library file, 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);
        ...
    }
});

getAddonByID()的第一个参数需要替换为您的加载项ID 。这里的假设是你的加载项已经解压安装(install.rdf中指定的< em:unpack> true< / em:unpack> 不是要加载的磁盘上的文件。

The first parameter to getAddonByID() needs to be replaced by the ID of your add-on of course. And the assumption here is that your add-on is installed unpacked (<em:unpack>true</em:unpack> specified in install.rdf) because otherwise there won't be a file on disk to be loaded.

这篇关于引用一个二进制组件到js-ctypes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆