收集需要构建的索引的类型
(stream *Stream, combineStruct *model.Descriptor)
| 244 | |
| 245 | // 收集需要构建的索引的类型 |
| 246 | func 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 | |
| 283 | func init() { |
| 284 |