-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathget_functions.py
More file actions
executable file
·58 lines (41 loc) · 1.09 KB
/
get_functions.py
File metadata and controls
executable file
·58 lines (41 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/python3
import sys, os, re
def usage():
print("{0} cppfilename".format(sys.argv[0]))
if len(sys.argv) < 2:
usage()
sys.exit(1)
_filename = sys.argv[1]
filename = _filename
module = "myModule"
f = open(sys.argv[1], encoding='utf-8', errors='ignore')
txt = f.read()
f.close()
txt = re.sub("//.*\n","",txt)
txt = re.sub(",\n",",",txt)
filename = "tmp.{0}".format(sys.argv[1])
f = open(filename,"w")
f.write(txt)
f.close()
cmd = 'ctags -x --_xformat="%K#%N#%C" {0} | grep function'.format(filename)
txt = os.popen(cmd).read()
l = re.findall("function#.*#.*[(].*[)]",txt)
txt = """#include "{0}"
#include <emscripten/bind.h>
using namespace emscripten;
EMSCRIPTEN_BINDINGS({1}""".format(_filename, module) + "){\n"
for i in l:
try:
nl = i.split('#')
txt += '\tfunction("{0}",&{0});\n'.format(nl[1])
except:
pass
txt += "}\n"
filename = filename.replace("tmp.","")
# filename = "_" + re.findall("\w+",filename)[0] + ".cc"
filename = "main.cc"
f = open(filename, "w")
f.write(txt)
f.close()
os.popen("cat {0} | uniq > tmpf && mv tmpf {0}".format(filename)).read()
os.popen("rm tmp*")