#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;
}
留意log函数里参数的获取
v8学习---添加带参数js全局函数
最新推荐文章于 2022-09-29 16:06:04 发布