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

Function printTableLua

v2/printer/lua.go:80–185  ·  view source on GitHub ↗
(g *Globals, stream *Stream, tab *model.Table)

Source from the content-addressed store, hash-verified

78}
79
80func printTableLua(g *Globals, stream *Stream, tab *model.Table) bool {
81
82 stream.Printf(" %s = {\n", tab.LocalFD.Name)
83
84 // 遍历每一行
85 for rIndex, r := range tab.Recs {
86
87 // 每一行开始
88 stream.Printf(" { ")
89
90 // 遍历每一列
91 for rootFieldIndex, node := range r.Nodes {
92
93 if node.IsRepeated {
94 stream.Printf("%s = { ", node.Name)
95 } else {
96 stream.Printf("%s = ", node.Name)
97 }
98
99 // 普通值
100 if node.Type != model.FieldType_Struct {
101
102 if node.IsRepeated {
103
104 // repeated 值序列
105 for arrIndex, valueNode := range node.Child {
106
107 stream.Printf("%s", valueWrapperLua(g, node.Type, valueNode))
108
109 // 多个值分割
110 if arrIndex < len(node.Child)-1 {
111 stream.Printf(", ")
112 }
113
114 }
115 } else {
116 // 单值
117 valueNode := node.Child[0]
118
119 stream.Printf("%s", valueWrapperLua(g, node.Type, valueNode))
120
121 }
122
123 } else {
124
125 // 遍历repeated的结构体
126 for structIndex, structNode := range node.Child {
127
128 // 结构体开始
129 stream.Printf("{ ")
130
131 // 遍历一个结构体的字段
132 for structFieldIndex, fieldNode := range structNode.Child {
133
134 // 值节点总是在第一个
135 valueNode := fieldNode.Child[0]
136
137 stream.Printf("%s= %s", fieldNode.Name, valueWrapperLua(g, fieldNode.Type, valueNode))

Callers 1

RunMethod · 0.85

Calls 2

valueWrapperLuaFunction · 0.85
PrintfMethod · 0.80

Tested by

no test coverage detected