Created
January 17, 2018 02:30
-
-
Save trolldbois/af7fee01b1afa13a74c196fefceeda93 to your computer and use it in GitHub Desktop.
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
import ctypeslib | |
from ctypeslib.codegen import clangparser | |
from ctypeslib.codegen import codegenerator | |
def gen_python_bindings(outdir, path): | |
# TODO: Make it configurable | |
clang_opts = ["-I/usr/local/include/libr/", "-I/usr/local/include/"] | |
# | |
pyout = StringIO() | |
fname = os.path.splitext(os.path.basename(path))[0] | |
# Use clang_opts here | |
parser = clangparser.Clang_Parser(flags = clang_opts) | |
items = parser.parse(path) | |
if items is None: | |
print("Error parsing {0} file!\n".format(fname)) | |
return False | |
gen = codegenerator.Generator(pyout) | |
# See ctypeslib/clang2py.py for more options | |
gen.generate(parser, items, flags=[], verbose=True) | |
outfname = outdir + "/" + fname + ".py" | |
with fopen(outfname, "w") as f: | |
f.write(pyout.getvalue()) | |
pyout.close() | |
return True | |
pyout.close() | |
print("Cannot write {0}.py file!\n".format(fname)) | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment