Google V8编程详解附录
Google V8编程详工具函数
头文件:utils.h
- #ifndef UTILS_H_
- #define UTILS_H_
- #include "v8.h"
- #include <iostream>
- using namespace v8;
- using namespace std;
- v8::Handle<v8::String> ReadJS(const char* name);
- void printValue(Handle<Value> result);
- #endif
- ReadJS
- v8::Handle<v8::String> ReadJS(const char* name) {
- FILE* file = fopen(name, "rb");
- if (file == NULL) {
- return v8::Handle<v8::String>();
- }
- fseek(file, 0, SEEK_END);
- int size = ftell(file);
- rewind(file);
- char* chars = new char[size + 1];
- chars[size] = '\0';
- for (int i = 0; i < size;) {
- int read = fread(&chars[i], 1, size - i, file);
- i += read;
- }
- fclose(file);
- v8::Handle<v8::String> result = v8::String::New(chars, size);
- delete[] chars;
- return result;
- }
- printValue
- void printValue(Handle<Value> result) {
- //感谢downmooner兄的提醒,这个String::Utf8Value str(result)的确让这段代码
- //南辕北辙
- //String::Utf8Value str(result);
- // just construct the "result" script
- Handle<Script> script = Script::Compile(String::New("result"));
- result = script->Run();
- cout << *String::Utf8Value(result) << endl;
- }
版权申明:
转载文章请注明原文出处,任何用于商业目的,请联系本人:hyman_tan@126.com
Google V8编程详解附录的更多相关文章
- Google V8编程详解(五)JS调用C++
http://blog.csdn.net/feiyinzilgd/article/details/8453230 最近由于忙着解决个人单身的问题,时隔这么久才更新第五章. 上一章主要讲了Google ...
- Google V8编程详解(四)Context
http://blog.csdn.net/feiyinzilgd/article/details/8266780 上一章,比较略提了下V8的Context.本章将详细的讲解下Context的概念以及用 ...
- Google V8编程详解(三)Handle & HandleScope
上一章简单的演示了一个Helloworld Demo.里面涉及到了V8的一些基本类型和概念,本章将围绕这个Demo对V8的基本类型和相关概念进行讲解. 这里还是先把Demo贴出来便于后面分析: #in ...
- Google V8编程详解(序)Cloud App
此系列文章转载于此http://blog.csdn.net/feiyinzilgd/article/details/8247723 应用程序发展到今天,应用程序的概念也在不断地发生着 ...
- Google V8编程详解(二)HelloWorld
转自http://blog.csdn.net/feiyinzilgd/article/details/8248448 上一章讲到了V8的编译和安装,这一章开始从一个demo着手. 这里选用了官方文档的 ...
- Google V8编程详解(一)V8的编译安装(Ubuntu)
V8的编译比较简单,需要同时安装git和svn. 下载V8源码: git clone git://github.com/v8/v8.git v8 && cd v8 切换到最新版本: g ...
- 前端后台以及游戏中使用Google Protocol Buffer详解
前端后台以及游戏中使用Google Protocol Buffer详解 0.什么是protoBuf protoBuf是一种灵活高效的独立于语言平台的结构化数据表示方法,与XML相比,protoBuf更 ...
- HBase 协处理器编程详解,第二部分:客户端代码编写
实现 Client 端代码 HBase 提供了客户端 Java 包 org.apache.hadoop.hbase.client.coprocessor.它提供以下三种方法来调用协处理器提供的服务: ...
- Linux的SOCKET编程详解(转)
Linux的SOCKET编程详解 1. 网络中进程之间如何通信 进 程通信的概念最初来源于单机系统.由于每个进程都在自己的地址范围内运行,为保证两个相互通信的进 程之间既互不干扰又协调一致工作,操作系 ...
随机推荐
- 拥有的50个CSS代码片段(上)
1. CSS 重置 ;;;font-size: 100%; font: inherit; vertical-align: baseline; outline: none; -webkit-box-si ...
- not子查询中有null值的时候 not in 会失效
not in子查询中有null值的时候 not in 会失效 但是 in 的子查询中有null的 不会失效
- OAF_开发系列24_实现OAF更新记录显示Record History(案例)
20150716 Created By BaoXinjian
- PHP中include和require的区别详解
1.概要 require()语句的性能与include()相类似,都是包括并运行指定文件.不同之处在于:对include()语句来说,在执行文件时每次都要进行读取和评估:而对于require()来说, ...
- Django 之 ForeignKey、ManyToMany的访问方式
1.ForeignKey 情况I: from django.db import models class Blog(models.Model): pass class Entry(models.Mod ...
- PHP Warning: PHP Startup: in Unknown on line 0
Windows平台启动php后,出现PHP Warning: PHP Startup: in Unknown on line 0解决方案:这个问题是由于php.ini中没有开启(去掉注释符号)ph ...
- Webpack 入门指南 - 3. Hello, Angular2!
Webpack 入门指南 - 1.安装 Webpack 入门指南 - 2.模块 这一次,我们使用 Webpack 来打包 Angular 2 的应用. 与官方的 Hello, Angular 2 项目 ...
- Linux学习四:UDP编程(上)
关于UDP和TCP对比优缺,这里就不说了. 使用UDP代码所掉用的函数和用于TCP的函数非常类似,这主要因为套接口库在底层的TCP和UDP的函数上加了一层抽象,通过这层抽象使得编程更容易,但失去了一些 ...
- iOS在label上加横杠
UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(20, 50, 200, 50)]; [self.view addSubvi ...
- git笔记 常规使用
1. 创建分支 git checkout -b fetch_name 2. 添加快照进行登记 git add . 3.登记到仓库 git commit -m 'message' git comm ...