Skip to content

Instantly share code, notes, and snippets.

@BobGneu
Created May 16, 2014 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BobGneu/27ba3717d2442fac3d87 to your computer and use it in GitHub Desktop.
Save BobGneu/27ba3717d2442fac3d87 to your computer and use it in GitHub Desktop.
Example of object encapsulation
void Flathead::DefineLoggingFunctions(Local<ObjectTemplate> globalTemplate)
{
HandleScope scope(GetIsolate());
Handle<Context> context = Context::New(GetIsolate());
Context::Scope ContextScope(context);
Local<FunctionTemplate> log_tmp = FunctionTemplate::New(GetIsolate());
log_tmp->PrototypeTemplate()->Set(String::NewFromUtf8(GetIsolate(), "log", String::kInternalizedString), FunctionTemplate::New(GetIsolate(), Flathead::LogCallback));
log_tmp->PrototypeTemplate()->Set(String::NewFromUtf8(GetIsolate(), "display", String::kInternalizedString), FunctionTemplate::New(GetIsolate(), Flathead::DisplayCallback));
log_tmp->PrototypeTemplate()->Set(String::NewFromUtf8(GetIsolate(), "warning", String::kInternalizedString), FunctionTemplate::New(GetIsolate(), Flathead::WarningCallback));
log_tmp->PrototypeTemplate()->Set(String::NewFromUtf8(GetIsolate(), "error", String::kInternalizedString), FunctionTemplate::New(GetIsolate(), Flathead::ErrorCallback));
log_tmp->PrototypeTemplate()->Set(String::NewFromUtf8(GetIsolate(), "fatal", String::kInternalizedString), FunctionTemplate::New(GetIsolate(), Flathead::FatalCallback));
globalTemplate->Set(String::NewFromUtf8(GetIsolate(), "game"), log_tmp->GetFunction()->NewInstance(), ReadOnly);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment