Git Product home page Git Product logo

typescript2cxx's Introduction

TypeScript to C++

License

TypeScript2Cxx 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

Quick Start

  1. Build Project
npm install
npm run build
  1. Compile test.ts

create file test.ts

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}.`;
    }
}

const howard = new Employee("Howard", "Sales");
console.log(howard.ElevatorPitch);
node __out\main.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 "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;
}
  1. Compile it.
cl /W3 /GR /EHsc /std:c++latest /Fe:test.exe /I ../cpplib ../cpplib/core.cpp test.cpp
  1. Run it.
test.exe

Result:

Hello, my name is Howard and I work in Sales.

Enjoy it.

typescript2cxx's People

Contributors

asdalexander77 avatar oduzhar avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.