v8学习---添加带参数js全局函数

时间:2021-02-11 16:58:18
#include <v8.h> using namespace v8; void log(const v8::FunctionCallbackInfo<Value>& args) { String::AsciiValue ascii(args[0]); printf("%s\n", *ascii); } int main() { Isolate* isolate = Isolate::GetCurrent(); HandleScope handleScope(isolate); Handle<ObjectTemplate> global = ObjectTemplate::New(); global->Set(String::New("log"), FunctionTemplate::New(log)); Handle<Context> context = Context::New(isolate, NULL, global); Context::Scope context_scope(context); Handle<Script> script = Script::Compile(String::New("log('good')")); script->Run(); return 0; }