本文整理汇总了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;
}
示例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;
}