MCPcopy
hub / github.com/davyxu/tabtoy / genLuaIndexCode

Function genLuaIndexCode

v2/printer/lua.go:246–281  ·  view source on GitHub ↗

收集需要构建的索引的类型

(stream *Stream, combineStruct *model.Descriptor)

Source from the content-addressed store, hash-verified

244
245// 收集需要构建的索引的类型
246func genLuaIndexCode(stream *Stream, combineStruct *model.Descriptor) bool {
247
248 // 遍历字段
249 for _, fd := range combineStruct.Fields {
250
251 // 这个字段被限制输出
252 if fd.Complex != nil && !fd.Complex.File.MatchTag(".lua") {
253 continue
254 }
255
256 // 对CombineStruct的XXDefine对应的字段
257 if combineStruct.Usage == model.DescriptorUsage_CombineStruct {
258
259 // 这个结构有索引才创建
260 if fd.Complex != nil && len(fd.Complex.Indexes) > 0 {
261
262 // 索引字段
263 for _, key := range fd.Complex.Indexes {
264 mapperVarName := fmt.Sprintf("tab.%sBy%s", fd.Name, key.Name)
265
266 stream.Printf("\n-- %s\n", key.Name)
267 stream.Printf("%s = {}\n", mapperVarName)
268 stream.Printf("for _, rec in pairs(tab.%s) do\n", fd.Name)
269 stream.Printf("\t%s[rec.%s] = rec\n", mapperVarName, key.Name)
270 stream.Printf("end\n")
271 }
272
273 }
274
275 }
276
277 }
278
279 return true
280
281}
282
283func init() {
284

Callers 1

RunMethod · 0.85

Calls 2

MatchTagMethod · 0.80
PrintfMethod · 0.80

Tested by

no test coverage detected