#include <v8.h>
using namespace v8;
void get_name(const v8::FunctionCallbackInfo<Value>& args)
{
args.GetReturnValue().Set(String::New("Headool"));
}
int main()
{
Isolate* isolate = Isolate::GetCurrent();
HandleScope handleScope(isolate);
Handle<ObjectTemplate> global = ObjectTemplate::New();
global->Set(String::New("get_name"), FunctionTemplate::New(get_name));
Handle<Context> context = Context::New(isolate, NULL, global);
Context::Scope context_scope(context);
Handle<Script> script = Script::Compile(String::New("get_name()"));
Handle<Value> value = script->Run();
String::AsciiValue ascii(value);
printf("%s\n", *ascii);
return 0;
}
留意其中的:
args.GetReturnValue().Set(String::New("Headool"));