本文整理汇总了C++中v8::Persistent::Global方法的典型用法代码示例。如果您正苦于以下问题:C++ Persistent::Global方法的具体用法?C++ Persistent::Global怎么用?C++ Persistent::Global使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类v8::Persistent
的用法示例。
在下文中一共展示了Persistent::Global方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
std::string f(optarg);
include_files.push_back(find_include_file(f));
break;
}
case 'j':
javascript_filename = optarg;
break;
case 'h':
print_help();
exit(0);
case 'l':
if (!strcmp(optarg, "none")) {
location_store = NONE;
} else if (!strcmp(optarg, "array")) {
location_store = ARRAY;
} else if (!strcmp(optarg, "disk")) {
location_store = DISK;
} else if (!strcmp(optarg, "sparsetable")) {
location_store = SPARSETABLE;
} else {
std::cerr << "Unknown location store: " << optarg << " (available are: 'none, 'array', 'disk' and 'sparsetable')" << std::endl;
exit(1);
}
break;
case 'r':
attempt_repair = false;
break;
case '2':
two_passes = true;
break;
default:
exit(1);
}
}
if (javascript_filename.empty()) {
std::cerr << "No --javascript/-j option given" << std::endl;
exit(1);
}
if (optind >= argc) {
std::cerr << "Usage: " << argv[0] << " [OPTIONS] OSMFILE [SCRIPT_ARG ...]" << std::endl;
exit(1);
} else {
osm_filename = argv[optind];
}
if (two_passes && osm_filename == "-") {
std::cerr << "Can't read from stdin when in dual-pass mode" << std::endl;
exit(1);
}
Osmium::Framework osmium(debug);
Osmium::OSMFile infile(osm_filename);
v8::HandleScope handle_scope;
v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
global_template->Set(v8::String::New("print"), v8::FunctionTemplate::New(Osmium::Handler::Javascript::Print));
global_template->Set(v8::String::New("include"), v8::FunctionTemplate::New(Osmium::Handler::Javascript::Include));
global_context = v8::Persistent<v8::Context>::New(v8::Context::New(0, global_template));
v8::Context::Scope context_scope(global_context);
// put rest of the arguments into Javascript argv array
v8::Handle<v8::Array> js_argv = v8::Array::New(argc-optind-1);
for (int i=optind+1; i<argc; ++i) {
v8::Local<v8::Integer> ii = v8::Integer::New(i-(optind+1));
v8::Local<v8::String> s = v8::String::New(argv[i]);
js_argv->Set(ii, s);
}
global_context->Global()->Set(v8::String::New("argv"), js_argv);
Osmium::Javascript::Template::init();
Osmium::Handler::NodeLocationStore *handler_node_location_store;
if (location_store == ARRAY) {
handler_node_location_store = new Osmium::Handler::NLS_Array();
} else if (location_store == DISK) {
handler_node_location_store = new Osmium::Handler::NLS_Disk();
} else if (location_store == SPARSETABLE) {
handler_node_location_store = new Osmium::Handler::NLS_Sparsetable();
} else {
handler_node_location_store = NULL;
}
handler_javascript = new Osmium::Handler::Javascript(include_files, javascript_filename.c_str());
if (two_passes) {
Osmium::Handler::Multipolygon *handler_multipolygon = new Osmium::Handler::Multipolygon(attempt_repair, cbmp);
infile.read<DualPass1>(new DualPass1(handler_node_location_store, handler_multipolygon, handler_javascript));
infile.read<DualPass2>(new DualPass2(handler_node_location_store, handler_multipolygon, handler_javascript));
delete handler_multipolygon;
} else {
infile.read<SinglePass>(new SinglePass(handler_node_location_store, handler_javascript));
}
delete handler_javascript;
delete handler_node_location_store;
global_context.Dispose();
}
示例2: registerToContext
void regVariable::registerToContext(v8::Persistent<v8::Context> context){
context->Global()->Set(v8::String::New(name), data);
}