-
Notifications
You must be signed in to change notification settings - Fork 845
/
param_types.lua
executable file
·124 lines (101 loc) · 2.59 KB
/
param_types.lua
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env lua
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
-- file: param_types.lua
-- brief: utility to help pick-out LuaParser param types from C++ source
-- author: Dave Rodgers
--
-- notes:
-- example usage: ./param_types UnitDefHandler.cpp
--
-- Copyright (C) 2007.
-- Licensed under the terms of the GNU GPL, v2 or later.
--
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
require 'io'
require 'string'
local srcFile = arg[1]
if (srcFile == nil) then
error('usage: '..arg[0]..' <srcFile>')
end
local types = {
'Int',
'Bool',
'Float',
'Float3',
'String',
}
local maps = {}
local f, err = io.open(srcFile, 'r')
if (f == nil) then
error(err)
end
local text = f:read('*a')
local function collect_names(type)
local map = {}
local array = {}
f:seek('set')
for text in f:lines() do
for caller, result in string.gfind(text, '([%a%d_]*).Get'..type..'%("([^"]*)"') do
table.insert(array, { result, caller, text })
map[result] = true
end
end
table.sort(array, function(a, b) return a[1] < b[1] end)
maps[type] = map
return array
end
local function print_names(type, array)
print('local '..string.lower(type)..'Map = {')
for i, d in ipairs(array) do
local result = d[1]
local caller = d[2]
local line = string.gsub(d[3], '^%s*', '')
print(string.format(' %-24s = true, -- %s -- %s --',
result, caller, result))
end
print('}')
end
local function parse_type(type)
local array = collect_names(type)
print_names(type, array)
end
for _, type in ipairs(types) do
parse_type(type)
print()
end
print('return {')
for _, type in ipairs(types) do
local name = string.lower(type)..'Map'
print(string.format(' %-9s = %s,', name, name))
end
print('}')
print()
local function collect_subtables()
local array = {}
f:seek('set')
for text in f:lines() do
local s, e = string.find(text, 'SubTable')
if (s) then
print('-- SubTable: '..text)
end
end
end
collect_subtables()
for _, type1 in ipairs(types) do
for _, type2 in ipairs(types) do
if (type1 ~= type2) then
for name in pairs(maps[type1]) do
-- print(type1, type2, name)
if (type2[name] ~= nil) then
print(string.format(
'error("Type conflict: %s is both a %s and %s")',
name, type1, type2))
end
end
end
end
end
f:close()