Skip to content

Commit 5810f13

Browse files
committed
增加 nbind
1 parent 03120d5 commit 5810f13

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

libs/cpp.wiki

+51
Original file line numberDiff line numberDiff line change
@@ -3726,6 +3726,57 @@ int main(int argc, char* argv[])
37263726
}
37273727
</source>
37283728

3729+
<h4>nbind</h4>
3730+
3731+
Home:[https://github.com/charto/nbind]
3732+
3733+
把 C++ 代码编译为 JS 的 package。编译方式支持“原生二进制”或“asm.js”。
3734+
3735+
编译需要依赖 Node.js,运行环境支持 Node.js 或浏览器。
3736+
3737+
代码示例——C++ 代码
3738+
<source lang="cpp">
3739+
&#35;include <string>
3740+
&#35;include <iostream>
3741+
3742+
struct Greeter
3743+
{
3744+
static void sayHello(std::string name)
3745+
{
3746+
std::cout << "Hello, " << name << "\n";
3747+
}
3748+
};
3749+
3750+
// 建立绑定
3751+
&#35;include <nbind/nbind.h>
3752+
3753+
NBIND_CLASS(Greeter)
3754+
{
3755+
method(sayHello);
3756+
}
3757+
</source>
3758+
3759+
代码示例——node.js 环境调用代码
3760+
<source lang="javascript">
3761+
var nbind = require("nbind");
3762+
var lib = nbind.init().lib;
3763+
lib.Greeter.sayHello("you");
3764+
</source>
3765+
3766+
代码示例——浏览器环境调用代码
3767+
<source lang="html">
3768+
<script src="nbind.js"></script>
3769+
<script>
3770+
nbind.init(
3771+
function(err, binding)
3772+
{
3773+
var lib = binding.lib;
3774+
lib.Greeter.sayHello("you");
3775+
}
3776+
);
3777+
</script>
3778+
</source>
3779+
37293780
----
37303781

37313782
= 18 (其它) =

0 commit comments

Comments
 (0)