这里是重点:Nodejs 是由v8 engine,libuv和内置模块组成,可以将v8 engine和 libuv看成一个库,两者是以源码的方式直接编译执行node中去的。
这是一个广泛的介绍,后面会详细介绍Nodejs的生态圈。
V8 engine
V8官方文档 https://developers.google.com/v8/intro
#include "include/v8.h" #include "include/libplatform/libplatform.h" using namespace v8; int main(int argc, char* argv[]) { // V8初试化. V8::InitializeICU(); Platform* platform = platform::CreateDefaultPlatform(); V8::InitializePlatform(platform); V8::Initialize(); // 创建isolate. Isolate* isolate = Isolate::New(); { Isolate::Scope isolate_scope(isolate); // 创建HandleScope. HandleScope handle_scope(isolate); // 创建context 环境. Local<Context> context = Context::New(isolate); // 引入环境. Context::Scope context_scope(context); // 创建字符串. Local<String> source = String::NewFromUtf8(isolate, "'Hello' + ', World!'"); // 编译字符串. Local<Script> script = Script::Compile(source); // Run,并且获取返回值. Local<Value> result = script->Run(); // 转换为utf8,并且打印出来. String::Utf8Value utf8(result); printf("%s\n", *utf8); } // 关掉v8. isolate->Dispose(); V8::Dispose(); V8::ShutdownPlatform(); delete platform; return 0; }