-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ODuzhar
committed
Mar 29, 2020
1 parent
c729379
commit 7de4f4e
Showing
8 changed files
with
376 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
TypeScript to C++ | ||
=========================== | ||
|
||
License | ||
------- | ||
|
||
TypeScriptCxx is licensed under the MIT license. | ||
|
||
Chat Room | ||
--------- | ||
|
||
Want to chat with other members of the TypeScript to C++ community? | ||
|
||
[![Join the chat at https://gitter.im/ASDAlexander77/TypeScript2Cxx](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/TypeScriptCpp/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
|
||
|
||
Quick Start | ||
----------- | ||
|
||
0) install | ||
|
||
``` | ||
node -i typescript-cxx | ||
``` | ||
|
||
|
||
1) Compile test.ts | ||
|
||
create file test.ts | ||
|
||
```TypeScript | ||
class Person { | ||
protected name: string; | ||
constructor(name: string) { this.name = name; } | ||
} | ||
|
||
class Employee extends Person { | ||
private department: string; | ||
|
||
constructor(name: string, department: string) { | ||
super(name); | ||
this.department = department; | ||
} | ||
|
||
public get ElevatorPitch() { | ||
return `Hello, my name is ${this.name} and I work in ${this.department}.`; | ||
} | ||
} | ||
|
||
let howard = new Employee("Howard", "Sales"); | ||
console.log(howard.ElevatorPitch); | ||
``` | ||
|
||
``` | ||
node __out\maian.js test.ts | ||
``` | ||
|
||
Now you have test.cpp and test.h | ||
|
||
test.h: | ||
``` | ||
#ifndef TEST_H | ||
#define TEST_H | ||
#include "core.h" | ||
using namespace js; | ||
class Person; | ||
class Employee; | ||
class Person : public object { | ||
public: | ||
string name; | ||
Person(string name); | ||
}; | ||
class Employee : public Person { | ||
public: | ||
string department; | ||
Employee(string name, string department); | ||
virtual any get_ElevatorPitch(); | ||
Employee(string name); | ||
}; | ||
extern Employee* howard; | ||
#endif | ||
``` | ||
|
||
test.cpp: | ||
``` | ||
#include "test.h" | ||
using namespace js; | ||
Person::Person(string name) { | ||
this->name = name; | ||
} | ||
Employee::Employee(string name, string department) : Person(name) { | ||
this->department = department; | ||
} | ||
any Employee::get_ElevatorPitch() | ||
{ | ||
return cast<any>("Hello, my name is "_S + this->name + " and I work in "_S + this->department + "."_S); | ||
} | ||
Employee::Employee(string name) : Person(name) { | ||
} | ||
Employee* howard = new Employee("Howard"_S, "Sales"_S); | ||
void Main(void) | ||
{ | ||
console->log(howard->get_ElevatorPitch()); | ||
} | ||
int main(int argc, char** argv) | ||
{ | ||
Main(); | ||
return 0; | ||
} | ||
``` | ||
|
||
2) Compile it. | ||
|
||
cl /W3 /GR /EHsc /std:c++latest /Fe:test.exe /I ../cpplib ../cpplib/core.cpp test.cpp | ||
|
||
3) Run it. | ||
|
||
``` | ||
test.exe | ||
``` | ||
|
||
Result: | ||
``` | ||
Hello, my name is Howard and I work in Sales. | ||
``` | ||
|
||
Enjoy it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
TypeScript to C++ | ||
=========================== | ||
|
||
License | ||
------- | ||
|
||
TypeScriptCxx is licensed under the MIT license. | ||
|
||
Quick Start | ||
----------- | ||
|
||
0) install | ||
|
||
``` | ||
node -i typescript-cxx | ||
``` | ||
|
||
|
||
1) Compile test.ts | ||
|
||
create file test.ts | ||
|
||
```TypeScript | ||
class Person { | ||
protected name: string; | ||
constructor(name: string) { this.name = name; } | ||
} | ||
|
||
class Employee extends Person { | ||
private department: string; | ||
|
||
constructor(name: string, department: string) { | ||
super(name); | ||
this.department = department; | ||
} | ||
|
||
public get ElevatorPitch() { | ||
return `Hello, my name is ${this.name} and I work in ${this.department}.`; | ||
} | ||
} | ||
|
||
let howard = new Employee("Howard", "Sales"); | ||
console.log(howard.ElevatorPitch); | ||
``` | ||
|
||
``` | ||
tsc-cxx test.ts | ||
``` | ||
|
||
Now you have test.cpp and test.h | ||
|
||
test.h: | ||
``` | ||
#ifndef TEST_H | ||
#define TEST_H | ||
#include "core.h" | ||
using namespace js; | ||
class Person; | ||
class Employee; | ||
class Person : public object { | ||
public: | ||
string name; | ||
Person(string name); | ||
}; | ||
class Employee : public Person { | ||
public: | ||
string department; | ||
Employee(string name, string department); | ||
virtual any get_ElevatorPitch(); | ||
Employee(string name); | ||
}; | ||
extern Employee* howard; | ||
#endif | ||
``` | ||
|
||
test.cpp: | ||
``` | ||
#include "test.h" | ||
using namespace js; | ||
Person::Person(string name) { | ||
this->name = name; | ||
} | ||
Employee::Employee(string name, string department) : Person(name) { | ||
this->department = department; | ||
} | ||
any Employee::get_ElevatorPitch() | ||
{ | ||
return cast<any>("Hello, my name is "_S + this->name + " and I work in "_S + this->department + "."_S); | ||
} | ||
Employee::Employee(string name) : Person(name) { | ||
} | ||
Employee* howard = new Employee("Howard"_S, "Sales"_S); | ||
void Main(void) | ||
{ | ||
console->log(howard->get_ElevatorPitch()); | ||
} | ||
int main(int argc, char** argv) | ||
{ | ||
Main(); | ||
return 0; | ||
} | ||
``` | ||
|
||
2) Compile it. | ||
|
||
cl /W3 /GR /EHsc /std:c++latest /Fe:test.exe /I ../cpplib ../cpplib/core.cpp test.cpp | ||
|
||
3) Run it. | ||
|
||
``` | ||
test.exe | ||
``` | ||
|
||
Result: | ||
``` | ||
Hello, my name is Howard and I work in Sales. | ||
``` | ||
|
||
Enjoy it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/usr/bin/env node | ||
require('../lib/main.js') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"name": "typescript-cxx", | ||
"version": "1.0.0", | ||
"description": "TypeScript to C++ transpiler", | ||
"keywords": [ | ||
"typescript", | ||
"c++", | ||
"tsc-cxx", | ||
"transpiler" | ||
], | ||
"main": "main.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"bin": { | ||
"tsc-cxx": "./bin/tsc-cxx" | ||
}, | ||
"dependencies": { | ||
"cross-spawn": "^6.0.5", | ||
"fs-extra": "^7.0.1", | ||
"path": "^0.12.7", | ||
"source-map": "^0.7.3", | ||
"typescript": "^3.3.3333" | ||
}, | ||
"engines": { | ||
"node": ">=4.2.0" | ||
}, | ||
"files": [ | ||
"bin/", | ||
"lib/", | ||
"README.md" | ||
], | ||
"author": "Alexander Duzhar", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/ASDAlexander77/TypeScriptCxx/issues" | ||
}, | ||
"homepage": "https://github.com/ASDAlexander77/TypeScriptCxx/#readme" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
if exist packages goto :skip | ||
md packages | ||
:skip | ||
cd packages | ||
if exist tsc-cxx goto :skip2 | ||
md tsc-cxx | ||
:skip2 | ||
cd tsc-cxx | ||
if exist lib goto :skip3 | ||
md lib | ||
if exist bin goto :skip3 | ||
md bin | ||
if exist cpplib goto :skip3 | ||
md cpplib | ||
:skip3 | ||
|
||
cd ..\.. | ||
|
||
del "packages\tsc-cxx\lib\*.js" | ||
del "packages\tsc-cxx\lib\*.js.map" | ||
|
||
del "packages\tsc-cxx\cpplib\*.cpp" | ||
del "packages\tsc-cxx\cpplib\*.h" | ||
|
||
@call tsc -p ./ | ||
copy __out\*.js "packages\tsc-cxx\lib" | ||
copy __out\*.js.map "packages\tsc-cxx\lib" | ||
|
||
copy Playground\core.h "packages\tsc-cxx\cpplib" | ||
copy Playground\core.cpp "packages\tsc-cxx\cpplib" | ||
|
||
cd ..\.. |
Oops, something went wrong.