本文整理汇总了C++中Interpreter::evaluate方法的典型用法代码示例。如果您正苦于以下问题:C++ Interpreter::evaluate方法的具体用法?C++ Interpreter::evaluate怎么用?C++ Interpreter::evaluate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Interpreter
的用法示例。
在下文中一共展示了Interpreter::evaluate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
Object global(new GlobalImp());
Interpreter interp;
interp.setGlobalObject(global);
ExecState *exec = interp.globalExec();
MyObject *myObject = (MyObject *)NPN_CreateObject (myFunctionPtrs);
global.put(exec, Identifier("myInterface"), Instance::createRuntimeObject(Instance::CLanguage, (void *)myObject));
for (int i = 1; i < argc; i++) {
const char *code = readJavaScriptFromFile(argv[i]);
if (code) {
// run
Completion comp(interp.evaluate(code));
if (comp.complType() == Throw) {
Value exVal = comp.value();
char *msg = exVal.toString(exec).ascii();
int lineno = -1;
if (exVal.type() == ObjectType) {
Value lineVal = Object::dynamicCast(exVal).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);
}
}
}
NPN_ReleaseObject ((NPObject *)myObject);
} // end block, so that Interpreter and global get deleted
return ret ? 0 : 3;
}