简体   繁体   English

如何为本机代码库(C / C ++)编写自己的Javascript API(客户端)

[英]How to write my own Javascript API (client-side) for a native code library (C/C++)

I must develop a Web App with HTML 5 and Javascript for client side. 我必须为客户端开发具有HTML 5和Javascript的Web应用程序。 But i need to use the funcionalities that provides a client's native library (.dll/.so) to process some data on it´s machine with C/C++. 但是我需要使用提供客户端的本机库(.dll / .so)的功能来使用C / C ++在其计算机上处​​理某些数据。

I like to write my own API in Javascript to access native library, like NodeJS's addons define, but those addons only are accessible from NodeJS (server-side). 我喜欢用Javascript编写自己的API来访问本机库,例如NodeJS的插件定义,但是只能从NodeJS(服务器端)访问这些插件。 Also there is a well established NPAPI but seems that Google's PPAPI wants to replace it: I could not decide on any of them. 也有一个完善的NPAPI,但Google的PPAPI似乎希望替换它:我无法决定其中的任何一个。

Is there something similar to NodeJS's addons for client-side that allow me to focus only on C++, Javascript and HTML 5? 是否有一些类似于NodeJS客户端的插件,使我仅专注于C ++,Javascript和HTML 5?

Thanks. 谢谢。

Not in any general sense. 没有任何一般意义。 Addons for node.js are allowed because there is an implicit trust relationship between the author of the code and the person running it. 允许使用node.js附加组件,因为代码的作者和运行它的人之间存在隐式的信任关系。 (Indeed, they're usually the same person.) In web browsers, no such trust exists -- by browsing to a web site, you're letting whoever wrote that site run some code on your system. (实际上,他们通常是同一个人。)在Web浏览器中,不存在这种信任-通过浏览到网站,您可以让撰写该网站的人在系统上运行某些代码。 Since you (probably) don't trust them completely, what they can do in Javascript is restricted to a set of known safe actions. 由于您(可能)不完全信任它们,因此它们在Javascript中只能执行一系列已知的安全操作。 Loading DLLs is very much not in that set. 加载DLL 不在那个集合中。

As generalhenry noted in a comment, there are some projects like emscripten to compile native code to Javascript, or Google Native Client to run sandboxed native code in the browser, but these technologies are still restricted in capabilities, and are pretty immature still. 正如generalhenry在评论中指出的那样,有一些项目,例如emscripten可以将本机代码编译为Javascript,或者有Google Native Client可以在浏览器中运行沙盒本机代码,但是这些技术的功能仍然受到限制,并且还很不成熟。 Ultimately, you will need to come to terms with the fact that code running in a browser is going to be limited. 最终,您将需要接受以下事实:浏览器中运行的代码将受到限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM