Handling an identified Module in C

孤人 提交于 2019-12-25 07:30:13

问题


I have written a test addon (a non-instancing little hello world app) for Node.JS, and I am now playing around with plugin-able addons. I am currently trying to create a addon that can access the hello world addon's functions, as well as the hello world calling the plugin host addon with a registration of presence.

As of yet, the only way I can determine so far is for a .js file to require both addons, then a call to the Hello World addon for the registration, then the plugin-host call. So, in short the coding would look like:

var host = require('./pluginHost');
host.registerPlugin(require('./helloWorldPlugin').plugin());
host.registerPlugin(require('./fooBarBazPlugin').plugin());
host.registrationComplete();

In actuality, there might be a bit more configuration code, but this is more of a concept at the moment. So, given the code above, withing the pluginHost addon code, how could I access & download information from that object. Bare in mind, the plugin part of the code that is being parsed to the pluginHost would be a static collection of functions that would contain information about the other objects and classes available as well as a mainline IPC between the pluginHost and other plugins.


回答1:


Righto, discovered how to do it

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"));

    ...
}

With this example, by calling host.registerPlugin(require('./pluginObject')) will allow the pluginHost library to interface with it, and include it for other systems.



来源:https://stackoverflow.com/questions/17438824/handling-an-identified-module-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!