当前位置: 首页>>代码示例>>C++>>正文


C++ Global::put方法代码示例

本文整理汇总了C++中Global::put方法的典型用法代码示例。如果您正苦于以下问题:C++ Global::put方法的具体用法?C++ Global::put怎么用?C++ Global::put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Global的用法示例。


在下文中一共展示了Global::put方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char **argv)
{
    // expecting a filename
    if (argc < 2) {
        fprintf(stderr, "You have to specify at least one filename\n");
        return -1;
    }

    bool ret = true;
    {
        JSLock lock;

        // create interpreter w/ global object
        Global* global = new Global();
        RefPtr<Interpreter> interp = new Interpreter(global);
        ExecState *exec = interp->globalExec();

        MyObject *myObject = new MyObject();
        RefPtr<RootObject> root = RootObject::create(0, interp);
        global->put(exec, Identifier("myInterface"), Instance::createRuntimeObject(Instance::BalLanguage, (void *)myObject, root));

        for (int i = 1; i < argc; i++) {
            const char *code = readJavaScriptFromFile(argv[i]);

            if (code) {
                // run
                Completion comp(interp->evaluate("", 0, code));

                /*if (comp.complType() == Throw) {
                    JSValue *exVal = comp.value();
                    char *msg = exVal->toString(exec).ascii();
                    int lineno = -1;
                    if (exVal->type() == ObjectType) {
                        JSValue *lineVal = exVal->getObject()->get(exec, Identifier("line"));
                        if (lineVal->type() == NumberType)
                            lineno = int(lineVal->toNumber(exec));
                    }
                    if (lineno != -1)
                        fprintf(stderr,"Exception, line %d: %s\n",lineno,msg);
                    else
                        fprintf(stderr,"Exception: %s\n",msg);
                    ret = false;
                }
                else if (comp.complType() == ReturnValue) {
                    char *msg = comp.value()->toString(interp->globalExec()).ascii();
                    fprintf(stderr,"Return value: %s\n",msg);
                }*/
            }
        }

        delete myObject;

    } // end block, so that Interpreter and global get deleted

    return ret ? 0 : 3;
}
开发者ID:jackiekaon,项目名称:owb-mirror,代码行数:56,代码来源:testbalbindings.cpp

示例2: main

int main(int argc, char **argv)
{
    // expecting a filename
    if (argc < 2) {
        fprintf(stderr, "You have to specify at least one filename\n");
        return -1;
    }

    bool ret = true;
    {
        JSLock lock;

        // create interpreter w/ global object
        Global* global = new Global();
        RefPtr<Interpreter> interp = new Interpreter(global);
        ExecState *exec = interp->globalExec();

        MyObject *myObject = new MyObject();
        RefPtr<RootObject> root = RootObject::create(0, interp);
        global->put(exec, Identifier("myInterface"), Instance::createRuntimeObject(Instance::BalLanguage, (void *)myObject, root));

        for (int i = 1; i < argc; i++) {
            const char *code = readJavaScriptFromFile(argv[i]);

            if (code) {
                // run
                Completion comp(interp->evaluate("", 0, code));
            }
        }

        delete myObject;

    } // end block, so that Interpreter and global get deleted

    return ret ? 0 : 3;
}
开发者ID:Chingliu,项目名称:EAWebkit,代码行数:36,代码来源:testbalbindings.cpp


注:本文中的Global::put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。