neutrinoscript
Version:
Like C for Javascript
133 lines (89 loc) • 2.01 kB
Markdown
Compile JS like C
=================
For local installation, run the following command:
```
npm install compile-js-like-c --save
```
For global installation, run the following command:
```
npm install -g compile-js-like-c
```
If you have installed this package in global, you can run "compile-like-c" and pass your main file and output file in arguments.
```
compile-like-c mainFile.js outputFile.js
```
```js
var compiler = require("compile-js-like-c");
compiler.compile("file.js", [ options, ] function(err, result) {
if (err)
return console.log(err);
console.log(result);
});
```
This are the defaults options. You can modify this by passing an option object in "compiler.compile"
```js
var options = {
// Write numbers in hexadcimal in #enum
enumHex: true,
// Consider every line stating with '#' as a comment
commentEscape: true,
// Trim include files
trimIncludes: true,
// Limits of empty following lines (0 = no limit)
spaceLineLimit: 0
};
```
```c
```
Include and parse a file.
```c
// Define a constant
// Define a macro
```
Create a constant or a macro.
```c
```
Delete a constant or a macro.
```c
// Do stuff
// Do other stuff
// Do stuff
```
Condition: do stuff if the constant is defined/undefined
```c
//# One line comment
/*#
Multi-line comment
#*/
```
This comments will be delete in the compiled file.
```c
// Here BIT0_B = 0, BIT0_C = 1, BIT0_D = 2, BIT0_E = 3
BIT0_B, BIT0_C, BIT0_D, BIT0_E
```
C like enumeration.