Created
September 4, 2020 15:44
-
-
Save redhog/94de90c3d4d9597c7ca7d33753a2080d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#! /usr/bin/env python | |
# | |
# Run this before running this script | |
# pip install CppHeaderParser | |
# Run as python gen.py header.h | |
# Prints C file with printer-funbctions. | |
import json, CppHeaderParser, sys | |
cppHeader = CppHeaderParser.CppHeader(sys.argv[1]) | |
header = json.loads(cppHeader.toJSON()) | |
res = "" | |
for name, defi in header["classes"].items(): | |
res += "void print_%s(%s *o) {\n" % (name, name) | |
for prop in defi["properties"]["public"]: | |
if prop["type"] == "int": | |
res += ' printf("%s=%%d\\n", o.%s);\n' % (prop["name"], prop["name"]) | |
elif prop["type"] == "char *": | |
res += ' printf("%s=%%s\\n", o.%s);\n' % (prop["name"], prop["name"]) | |
res += "}\n" | |
print(res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Above code is in the public domain, or where that is not legally possible, CC0. Have fun :)