我已经为Node.JS编写了一个测试插件(一个非实例化的小hello world应用程序),现在我正在玩可插入插件。我当前正在尝试创建一个可访问hello world addon功能的插件,以及hello world调用具有注册状态的插件主机插件。
到目前为止,到目前为止,我唯一可以确定的方法是.js文件需要两个插件,然后调用Hello World插件进行注册,再调用plugin-host。因此,简而言之,编码看起来像:
var host = require('./pluginHost');
host.registerPlugin(require('./helloWorldPlugin').plugin());
host.registerPlugin(require('./fooBarBazPlugin').plugin());
host.registrationComplete();
实际上,可能会有更多的配置代码,但是目前这只是一个概念。因此,鉴于上面的代码,加上
pluginHost
附加代码,我该如何从该对象访问和下载信息。简而言之,正在解析到pluginHost
的代码的插件部分将是一个静态的函数集合,其中将包含有关其他可用对象和类以及pluginHost
与其他之间的主线IPC的信息。 plugins
。 最佳答案
Righto,发现了如何做
C ++:
Handle<Value> registerPlugin(const Arguments &args) {
HandleScope scope;
Handle<Object> This = args.This();
Handle<Context> context = Context::New();
Handle<Object> object = This->Get(String::New("ObjectValueIWantKey"))->ToObject();
if (object == Undefined()) {
return Undefined();
}
Handle<Value> functionName = object->Get(String::New("SomeFunctionName"));
if (functionName->IsFunction()) {
Handle<Function> function = Handle<Function>::Cast(functionName);
Handle<Value> fargs[1] = { String::New("ARG") };
Handle<Value> methodResult = function->Call(object, 1, fargs);
}
Handle<Value> variableResult = object->Get(String::New("SomePropertyName"));
...
}
在此示例中,通过调用
host.registerPlugin(require('./pluginObject'))
将允许pluginHost
库与其进行接口,并将其包括在其他系统中。关于c - 在C中处理已识别的模块,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17438824/