-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcocos_dict.rb
161 lines (157 loc) · 5.83 KB
/
cocos_dict.rb
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
require "set"
#path = '~/Game/cocos2d-x/cocos/scripting/lua-bindings/auto/api/'
path = './cocos3.0' ## the new api path, the top path will lost some api
## so use the new dir api path some api are in the manual cpp define
curDir = ''
hash = {}
if ARGV.length == 0
#path = ARGV.first
curDir = Dir.pwd
path = File.expand_path path
Dir.chdir path
other=[]
Dir.glob("*.lua") do |afile|
fname = File.basename(afile,'.lua')
# if fname.include? '_api'
if fname == 'cc' or fname == 'ccs' or fname == 'ccui' or fname == 'sp'
open(afile, 'r') do |file|
file.readlines.each do |readline|
readline.match('@module\s\w+') do |m|
mname = m.to_s.split(' ')[1]
hash[mname] = hash[mname] || []
end
readline.match('@field\s.+') do |field|
a = field.to_s.split(' ')
key = ''
value = ''
a.each_index do |index|
if index == 1
if a[index].include? ']'
sidx = a[index].index('#') + 1
eidx = a[index].index(']')
key = a[index][sidx...eidx]
if hash.key? key == false
hash[key] = []
end
end
elsif index == 2
if a[index].include? '#'
m = a[index].match('\w+#\w+')
if m.nil?
value = a[3]
else
m.to_a.each do |item|
eidx = a[index].index('#')
value = a[index][0...eidx]
end
end
# a[index].match('\w+#\w+') do |m|
# puts m
# if m.nil?
# value = a[3]
# puts value
# else
# eidx = a[index].index('#')
# value = a[index][0...eidx]
# end
# end
end
end
if key.empty? || value.empty?
next
end
hash[key] << "#{key}.#{value}"
end
end
end
end
else
if fname.include?("_api") == false
other << afile
end
end
end
#export the data to dict file
Dir.chdir(curDir)
open('cocoslua.dict','w') do |f|
hash.each_pair do |key,value|
f.write("#{key}\n\n")
value.sort!.each do |v|
f.write("#{v}\n")
end
f.write("\n")
end
if other.empty? == false
other.sort!
other.each do |file|
p = File.basename(file,'.lua')
f.write("#{p}\n")
end
f.write("\n")
end
end
#
# now write the other methods to the lua dict file
#
#
Dir.chdir(path)
if other.empty? == false
s = Set.new
other.each do |item|
text = []
open(item,'r') do |file|
text = file.readlines
end
text.reverse!
len = text.length
params = []
(1..len).each do |i|
if text[i].nil?
next
else
text[i].match('@param\s.+') do |param|
a = param.to_s.split(' ')
if a[1].include? '#'
sidx = a[1].index('#') + 1
eidx = a[1].length
params << a[1][sidx..eidx]
else
params << a[1]
end
end
text[i].match('@field\s.+') do |field|
s << field.to_s.split(' ')[3]
end
text[i].match('@function\s.+') do |fun|
func = fun.to_s.split(' ').last
if params.empty? == false
s << func
func << '('
i = 1
l = params.length
params.reverse_each do |x|
if i == l then func << x end
if i != l then func << "#{x}, " end
i += 1
end
func << ')'
s << func
params.clear
else
s << func
end
end
end
end
end
Dir.chdir(curDir)
open('cocoslua.dict','a') do |file|
a = s.to_a
a.sort!.each do |item|
file.write "#{item}\n"
end
end
end
else
puts 'please enter the lua script api example: $COCOS_ROOT/cocos/scripting/lua-binding/auto/api path'
end