插件示例
🌐 Addon examples
以下是一些示例插件,旨在帮助开发者入门。这些示例使用了 V8 API。有关各种 V8 调用的帮助,请参考在线 V8 参考;有关例如句柄、作用域、函数模板等使用的几个概念的解释,请参考 V8 的 嵌入指南。
🌐 The following are some example addons intended to help developers get started. The examples use the V8 APIs. Refer to the online V8 reference for help with the various V8 calls, and V8's Embedder's Guide for an explanation of several concepts used such as handles, scopes, function templates, etc.
每个例子都使用以下 binding.gyp 文件:
🌐 Each of these examples uses the following binding.gyp file:
{
"targets": [
{
"target_name": "addon",
"sources": [ "addon.cc" ]
}
]
} 在有多个 .cc 文件的情况下,只需将额外的文件名添加到 sources 数组中即可:
🌐 In cases where there is more than one .cc file, simply add the additional
filename to the sources array:
"sources": ["addon.cc", "myexample.cc"] 一旦 binding.gyp 文件准备好,就可以使用 node-gyp 配置并构建示例插件:
🌐 Once the binding.gyp file is ready, the example addons can be configured and
built using node-gyp:
node-gyp configure build