Skip to content
This repository was archived by the owner on Nov 24, 2023. It is now read-only.

itsvic-dev/py2cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

py2cpp

because it's (was) Pride 2022 so it's time to be gay do crimes

simply run with python py2cpp.py file.py and get file.cpp back!

disclaimer

won't work on a lot of stuff and will probably produce lots of garbage code so do expect that, i probably won't work on this but issues and pull requests are welcome!

this will probably require some restructuring to tidy up the code as rn everything's in one file and it'll get very crowded with more features

example code

class Person:
    name: str
    age: int

    def __init__(self, name: str):
        self.name = name
    
    def set_age(self, age: int):
        self.age = age
    
    def greet(self):
        print("Hi", self.name + ", you're", self.age, "right?")

if __name__ == "__main__":
    omame = Person("omame")
    omame.set_age(17)
    omame.greet()

will get transpiled to

#include <string>
#include <iostream>
class Person {
public:
    std::string name;
    int age;
    Person(std::string name) {
        this->name = name;
    }
    void set_age(int age) {
        this->age = age;
    }
    void greet() {
        std::cout << "Hi" << " " << this->name + ", you're" << " " << this->age << " " << "right?" << "\n";
    }
};
int main() {
    Person omame = Person("omame");
    omame.set_age(17);
    omame.greet();
    return 0;
}

About

Python to C++ transpiler.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages