zl程序教程

您现在的位置是:首页 >  工具

当前栏目

chrome native client小试牛刀

Chrome native Client
2023-09-14 08:59:46 时间

1、安装native client sdk

    下载地址: http://commondatastorage.googleapis.com/nativeclient-mirror/nacl/nacl_sdk/naclsdk_win.exe

下载后安装在C:\native_client_sdk_0_5_1052

本次试验的两个关键目录project_templates,examples.其中project_templates包含一个模板代码生成,examples中包含示例代码。

2、安装Python

下载地址:http://www.python.org/ftp/python/2.7.2/python-2.7.2.msi
下载后安装到C:\Python27,在系统环境变量中的Path最后加上;C:\Python27

3、在chrome中启用native client

在chrome浏览器中地址栏输入about:flags 找到native client点击启动,重启浏览器;然后在浏览器地址栏输入about:plugins找到native client点击启动,无须重启浏览器

二、查看示例

进入C:\native_client_sdk_0_5_1052\examples,双击httpd.py,启动python的web server。

在chrome地址栏输入http://localhost:5103/index.html,可查看自带示例。

三、开发示例

1、创建工程

进入控制台:

cd C:\native_client_sdk_0_5_1052\project_templates

 init_project.py -n helloworld -d ../examples (-n 名称 -d目录)

这时在examples文件下多了一个helloworld目录。改目录有:

helloworld.cc c++代码

helloworld.html 网页代码

scons.bat 编译C++

2、修改代码

打开helloworld.html,新增

function moduleDidLoad() {

 HelloTutorialModule = document.getElementById(hello_tutorial);

 HelloTutorialModule.addEventListener(message, handleMessage, false);

 updateStatus(SUCCESS);

 //Send a message to the NaCl module.

 HelloTutorialModule.postMessage(hello);

 }

 


const char* const kHelloString = "hello"; // The string sent back to the browser upon receipt of a message // containing "hello". const char* const kReplyString = "hello from NaCl"; } // namespace

 

 

找到

// TODO(sdk_user): 1. Make this function handle the incoming message.

 

 

替换成

 

 if (!var_message.is_string())

 return;

 std::string message = var_message.AsString();

 pp::Var var_reply;

 if (message == kHelloString) {

 var_reply = pp::Var(kReplyString);

 PostMessage(var_reply);

 }

 

 

 


编译C++的native client module ,双击helloworld目录底下的scons.bat文件。

 

 

编译完成后,生成:

 

hello_tutorial_x86_32.nexe hello_tutorial_x86_32_dbg.nexe hello_tutorial_x86_64.nexe hello_tutorial_x86_64_dbg.nexe

进入C:\native_client_sdk_0_5_1052\examples

双击httpd.py

在chrome浏览器中输入地址:http://localhost:5103/helloworld/helloworld.html

得到从native client module返回的hello from NaCl

 


atom-shell: GitHub 开源的跨平台桌面应用框架(基于 Node.js 和 HTML 5) atom-shell是 GitHub 随 Atom 一起开源的跨操作系统(Windows,Linux,MacOS X)的利用 Web 技术(Node.js、JavaScript、HTML 5)开发桌面应用的框架。Atom即构建在 atom-shell 之上。