Debian Codegraph @

doc/scripts/findlua.py

raw
1 #!/usr/bin/env python
2 "Output all lua functions defined in the engine source code."
3
4 import os
5 import os, sys
6 from stat import *
7
8 # where to find the other stratagus tools
9 toolpath = os.path.dirname(sys.argv[0]) + '/'
10
11 def walktree(top, callback):
12 '''recursively descend the directory tree rooted at top,
13 calling the callback function for each regular file'''
14
15 for f in os.listdir(top):
16 pathname = os.path.join(top, f)
17 mode = os.stat(pathname)[ST_MODE]
18 if S_ISDIR(mode):
19 # It's a directory, recurse into it
20 walktree(pathname, callback)
21 elif S_ISREG(mode):
22 # It's a file, call the callback function
23 callback(pathname)
24 else:
25 # Unknown file type, print a message
26 print 'Skipping %s' % pathname
27
28 commands = []
29 reffiles = {}
30
31 def visitfile(file):
32 #print 'visiting', file
33 if file.endswith('.c'):
34 for line in open(file).read().split('\n'):
35 if not line.startswith('//'):
36 for part in line.split('lua_register(Lua, "')[1:]:
37 command = part.split('"')[0]
38 commands.append(command)
39 reffiles[command] = file
40
41 if __name__ == '__main__':
42 walktree(sys.argv[1], visitfile)
43
44 commands.sort()
45 for command in commands:
46 print command
47