Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly is JS2C?

I have recently started implementing v8 into my game engine, and I have chosen Node over bare-bone v8 and I have decided to build my game engine as a native node module. I have had many performance issues so far and I have paused development for further research.

I have came across Pixel Dust Game engine and one of the things I have noticed in its v8/Node bindings is these gigantic const char arrays that obviously are not generated by humans! and in its title I found /* this file automatically generated by js2c.py */.

I understand JS2C is a part of v8 and I have noticed these arrays in Node's source code as well. What are these? And how they may help me in Node module development?

Could you please also provide an example of its usage?

like image 301
Sepehr Avatar asked Oct 19 '25 09:10

Sepehr


2 Answers

From the v8 source you linked:

# This is a utility for converting JavaScript source code into C-style
# char arrays. It is used for embedded JavaScript code in the V8
# library.

I can't give any usage examples as I have never used it before.

like image 118
Ferdi265 Avatar answered Oct 22 '25 00:10

Ferdi265


JS2C, found in [node source]/tools/js2c.py and [v8 source]/tools/js2c.py, as I understand it, takes JavaScript and turns it into a compileable C++ array.
Format: js2c.py [c++ output file] [JS input file]


I actually have an issue on GitHub to try and figure out how to use it: https://github.com/nodejs/help/issues/1301
You might find some info from collaborators of that issue.

like image 43
JacobTDC Avatar answered Oct 21 '25 23:10

JacobTDC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!