https://github.com/mishamyrt/cppwriter
✍️ Iterative interface for generating C/C++ code from Python
https://github.com/mishamyrt/cppwriter
arduino cpp
Last synced: 5 months ago
JSON representation
✍️ Iterative interface for generating C/C++ code from Python
- Host: GitHub
- URL: https://github.com/mishamyrt/cppwriter
- Owner: mishamyrt
- License: mit
- Created: 2024-07-02T08:04:17.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-02T11:10:55.000Z (about 2 years ago)
- Last Synced: 2025-09-24T01:28:13.495Z (10 months ago)
- Topics: arduino, cpp
- Language: Python
- Homepage:
- Size: 13.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# C++ writer [](https://github.com/mishamyrt/cppwriter/actions/workflows/qa.yaml) [](https://badge.fury.io/py/cppwriter)
The library provides an iterative interface for generating C/C++ code from Python.
## Installation
```sh
pip install cppwriter
```
## Usage
```python
from cppwriter import FileBlock
file = FileBlock(indent_char=" ")
file.include("stdio.h", is_global=True)
file.line()
main = file.function("main", "int")
main.if_statement("PI > 4").line("return 1")
main.line("return 0")
print(str(file))
```
This will generate the following code:
```c
#include
int main() {
if (PI > 4) {
return 1;
}
return 0;
}
```
## Relationship to cwriter
When I started making this library I didn't know about the existence of cwriter. I came across it while searching for a package name, but decided to give up and still finish my version.