#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全局函數
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.