huenchao / DevOps

基本开发配置
1 stars 0 forks source link

2020-04计划 #2

Open huenchao opened 4 years ago

huenchao commented 4 years ago
  1. kafka node客户端 https://itnext.io/a-simple-guide-to-load-c-c-code-into-node-js-javascript-applications-3fcccf54fd32 2.faas服务落地规划
huenchao commented 4 years ago

参考书籍 《来一打c扩展》 、《nodecpp-ebook》

huenchao commented 4 years ago

https://v8docs.nodesource.com/node-10.15/ https://nodejs.org/api/addons.html

huenchao commented 4 years ago
  1. 在nodejs中,什么叫module? nodejs中,一个文件就是一个module. 流程:(1)Module.runMain() ---> (2) Module._load(process.argv[1], null, true); 其中(2): // Check the cache for the requested file. // 1. If a module already exists in the cache: return its exports object. // 2. If the module is native: call // NativeModule.prototype.compileForPublicLoader() and return the exports. // 3. Otherwise, create a new module for the file and save it to the cache. // Then have it load the file contents before returning its exports // object.
huenchao commented 4 years ago
inline void NODE_SET_METHOD(v8::Local<v8::Template> recv,
                            const char* name,
                            v8::FunctionCallback callback) {
  v8::Isolate* isolate = v8::Isolate::GetCurrent();
  v8::HandleScope handle_scope(isolate);
  v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate,
                                                                callback);
  v8::Local<v8::String> fn_name = v8::String::NewFromUtf8(isolate, name,
      v8::NewStringType::kInternalized).ToLocalChecked();
  t->SetClassName(fn_name);
  recv->Set(fn_name, t);
}
huenchao commented 4 years ago
inline void NODE_SET_METHOD(v8::Local<v8::Object> recv,
                            const char* name,
                            v8::FunctionCallback callback) {
  v8::Isolate* isolate = v8::Isolate::GetCurrent();
  v8::HandleScope handle_scope(isolate);
  v8::Local<v8::Context> context = isolate->GetCurrentContext();
  v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate,
                                                                callback);
  v8::Local<v8::Function> fn = t->GetFunction(context).ToLocalChecked();
  v8::Local<v8::String> fn_name = v8::String::NewFromUtf8(isolate, name,
      v8::NewStringType::kInternalized).ToLocalChecked();
  fn->SetName(fn_name);
  recv->Set(context, fn_name, fn).Check();
}