https://github.com/stringmanolo/cppjs
Some Javascript Sintax Sugar for C++
https://github.com/stringmanolo/cppjs
Last synced: 10 months ago
JSON representation
Some Javascript Sintax Sugar for C++
- Host: GitHub
- URL: https://github.com/stringmanolo/cppjs
- Owner: StringManolo
- Created: 2020-11-24T11:19:34.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2020-11-29T18:30:07.000Z (about 5 years ago)
- Last Synced: 2025-02-07T17:45:02.063Z (12 months ago)
- Language: C++
- Size: 774 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# cppjs
Some Javascript Sintax Sugar for C++
### Notice:
Since you can't declare global variables inside a function, the var keyword has nothing to do with var in javascript. The var keyword here is used as an alternative where the let keyword does not work.
var allow you to reasign the same variable to other data types.
When using let you may need to declare a new variable.
You should use let where you can, since most functions are designed to work with specific data types, where var is a unique data type holding other type inside.
Remember the purpouse of this library is not trying to implement javascript language, transpile or be a engine. It's made to program in C++, but using a short sintax and higher level approach.
If you want to develop using full javascript you should go for node.js, deno, quickjs, ducktape...
### Example:
```
#include "./headers.h"
#include
int main(int argc, char *argv[]) {
let word = "world";
console.log("Hello", word, "!");
var a = 12;
console.log("a:", a);
a = "Hello!";
console.log(a);
let myHtml = fetch("https://example.com");
console.log("Example Code:", myHtml);
fetchOptions.method = "POST";
fetchOptions.data = "name=StringManolo&pass=123";
myHtml = fetch("https://example.com");
console.log("Post Request return:", myHtml);
let myCsv = split("car, bike, motorbike, truck, airplane", ", ");
for(let i = 0; i < myCsv.size(); ++i) {
console.log("CSV N°", i+1 , ":", myCsv[i]);
}
console.log("Replacing hola from hola world to hello:",
replace("hola world!", "hola", "hello"));
console.log("CSV string:", join(myCsv, ","));
for(let vehicle in myCsv) {
console.log("Vehicle:", vehicle);
}
let add = function(let num1, let num2) {
return num1 + num2;
};
console.log("Add 7 + 8 using function:", add(7,8));
return 0;
}
```
Compile Linux:
```
g++ -o program main.cpp -lcurl
```
Compile Termux:
+ First Time:
```
mkdir ~/../usr/myPrograms && cd ~/../usr/myPrograms && git clone https://github.com/StringManolo/cppjs.git && cd cppjs
pkg install libcurl && pkg install termux-elf-cleaner && ./compile
```