All Projects → chexiongsheng → v8_embedding_test

chexiongsheng / v8_embedding_test

Licence: MIT license
No description, website, or topics provided.

Programming Languages

C++
36643 projects - #6 most used programming language
CMake
9771 projects
c
50402 projects - #5 most used programming language
objective c
16641 projects - #2 most used programming language
shell
77523 projects
Batchfile
5799 projects
javascript
184084 projects - #8 most used programming language

v8_embedding_test

《c++游戏服务器嵌入v8 js引擎胎教级教程》配套代码

!!! 注意:本示例库较老旧,正式生产使用,应到puerts官网取最新库代码: https://github.com/Tencent/puerts

测试环境:Ubuntu

v8下载

下载puerts编译好的配套v8库

解压到v8_embedding_test目录

helloworld项目编译运行

cd helloworld
mkdir build
cd build
cmake ..
make

./helloworld

puertstest项目编译运行

cd puertstest
mkdir build
cd build
cmake ..
make

./helloworld

nodeaddon项目运行

cd nodeaddon
npm install .
node hello.js

nodejstest项目运行

先编译libnode.so

git clone [email protected]:nodejs/node.git
cd node
./configure --shared
make -j4

拷贝nodejstest到node目录,拷贝puertstest/puerts目录到node/nodejstest目录

cd nodejstest
mkdir build
cd build
cmake ..
make

./embedtest

pesapitest

由于动态库加载仅实现了window版本(见([PesapiAddonLoad.cpp]pesapitest/pesapiv8impl/src/PesapiAddonLoad.cpp)),所以只能在window下运行

编译

cd pesapitest\pesv8app
make_win64.bat
cd pesapitest\pesaddon
make_win64.bat

运行

cd pesapitest\pesv8app
build64_v8\Release\helloworld.exe

输出

wrap by hand begin
Inc1024
wrap by hand end
Inc2048

说明

  • pesapitest\pesaddon是一个pesapi的扩展(动态库),理论上可以在任意实现了pesapi的环境运行,可以仅依赖于纯c的头文件pesapi.h以根据该头文件生成的pesapi_adpt.c文件。如果需要用c++模板绑定,则依赖puerts相关头文件。

  • pesv8app是个可执行程序,其嵌入了v8,并基于v8实现了pesapi(见[PesapiV8Impl.cpp]pesapitest/pesapiv8impl/src/PesapiV8Impl.cpp))

  • pesv8app通过pesapi_load_addon加载了dll,然后就可以通过loadCppType加载注册的类

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].