forked from trigrass2/v_repStubsGen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_lua_calltips.py
More file actions
39 lines (33 loc) · 1.28 KB
/
generate_lua_calltips.py
File metadata and controls
39 lines (33 loc) · 1.28 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
from sys import argv, exit
import re
if len(argv) != 5:
print('usage: {} <long-plugin-name> <short-plugin-name> <lua-file> <output-cpp-file>'.format(argv[0]))
exit(1)
longPlugName = argv[1]
shortPlugName = argv[2]
luafile = argv[3]
outfile = argv[4]
fun = None
args, rets = [], []
with open(outfile, 'w') as fout:
def output():
if fun:
f, fdesc = fun
calltip = (','.join(x[0] for x in rets)+('=' if rets else '')+'sim'+shortPlugName+'.'+f+'('+','.join(x[0] for x in args)+')')
if fdesc:
calltip += '\\n\\n' + fdesc
while calltip[-2:] == '\\n': calltip = calltip[:-2]
fout.write('simRegisterScriptCallbackFunctionE("sim{}.{}@{}", "{}", NULL);\n'.format(shortPlugName, f, longPlugName, calltip))
with open(luafile, 'r') as f:
for line in f:
m = re.match(r'\s*--\s*@([^\s]+)\s+([^\s]+)(.*)$', line)
if m:
key, value, desc = map(lambda s: s.strip(), m.groups())
if key == 'fun': fun = (value, desc)
elif key == 'arg': args.append((value, desc))
elif key == 'ret': rets.append((value, desc))
else:
output()
fun = None
args, rets = [], []
output()