本文介绍了是否有可能用C(不是C ++)使Node.js的扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个快速谷歌搜索产量至少一个教程编写 C ++的Hello World对于node.js的,但目前还不清楚是否有可能写出这样只使用C.假设这是可能的延伸,什么样的挑战/局限性,所以我会面对?

A quick google search yields at least one tutorial for writing a C++ "Hello World" for node.js, but it's unclear if it's possible to write such an extension using only C. Assuming it is possible, what challenges / limitations would I face?

推荐答案

您可以编写扩展的部分用C,如果你想,但你至少需要C ++ code的一个小一点粘合起来的C code。与节点。

You can write parts of your extension in C if you want, but you'll need at least a small bit of C++ code to glue together your C code with Node.

正如你会在你的HelloWorld已经看到,扩展依靠 v8.h node.h 头,里面有所有节点预计类。如果没有这些,你将不能够正确地创建JS对象输回节点。

As you will have seen in your HelloWorld, extensions rely on the v8.h and node.h headers, which have all of the classes that Node expects. Without those, you won't be able to properly create the JS object to export back to Node.

这就是说,你可以pretty容易只写一小部分的C ++函数,仅仅调用C函数,以及一些包装类C的结构。

That said, you can pretty easily just write a small set of C++ functions that just call C functions, and wrap some kind of C structure.

这篇关于是否有可能用C(不是C ++)使Node.js的扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-29 07:17
查看更多