@@ -48,6 +48,7 @@ func newLTable(acap int, hcap int) *LTable {
48
48
return tb
49
49
}
50
50
51
+ // Len returns length of this LTable.
51
52
func (tb * LTable ) Len () int {
52
53
if tb .array == nil {
53
54
return 0
@@ -63,13 +64,15 @@ func (tb *LTable) Len() int {
63
64
return 0
64
65
}
65
66
67
+ // Append appends a given LValue to this LTable.
66
68
func (tb * LTable ) Append (value LValue ) {
67
69
if tb .array == nil {
68
70
tb .array = make ([]LValue , 0 , defaultArrayCap )
69
71
}
70
72
tb .array = append (tb .array , value )
71
73
}
72
74
75
+ // Insert inserts a given LValue at position `i` in this table.
73
76
func (tb * LTable ) Insert (i int , value LValue ) {
74
77
if tb .array == nil {
75
78
tb .array = make ([]LValue , 0 , defaultArrayCap )
@@ -88,6 +91,7 @@ func (tb *LTable) Insert(i int, value LValue) {
88
91
tb .array [i ] = value
89
92
}
90
93
94
+ // MaxN returns a maximum number key that nil value does not exist before it.
91
95
func (tb * LTable ) MaxN () int {
92
96
if tb .array == nil {
93
97
return 0
@@ -100,6 +104,7 @@ func (tb *LTable) MaxN() int {
100
104
return 0
101
105
}
102
106
107
+ // Remove removes from this table the element at a given position.
103
108
func (tb * LTable ) Remove (pos int ) LValue {
104
109
if tb .array == nil {
105
110
return LNil
@@ -122,6 +127,9 @@ func (tb *LTable) Remove(pos int) LValue {
122
127
return oldval
123
128
}
124
129
130
+ // RawSet sets a given LValue to a given index without the __newindex metamethod.
131
+ // It is recommended to use `RawSetString` or `RawSetInt` for performance
132
+ // if you already know the given LValue is a string or number.
125
133
func (tb * LTable ) RawSet (key LValue , value LValue ) {
126
134
switch v := key .(type ) {
127
135
case LNumber :
@@ -152,6 +160,7 @@ func (tb *LTable) RawSet(key LValue, value LValue) {
152
160
tb .RawSetH (key , value )
153
161
}
154
162
163
+ // RawSetInt sets a given LValue at a position `key` without the __newindex metamethod.
155
164
func (tb * LTable ) RawSetInt (key int , value LValue ) {
156
165
if key < 1 || key >= MaxArrayIndex {
157
166
tb .RawSetH (LNumber (key ), value )
@@ -175,6 +184,7 @@ func (tb *LTable) RawSetInt(key int, value LValue) {
175
184
}
176
185
}
177
186
187
+ // RawSetString sets a given LValue to a given string index without the __newindex metamethod.
178
188
func (tb * LTable ) RawSetString (key string , value LValue ) {
179
189
if tb .strdict == nil {
180
190
tb .strdict = make (map [string ]LValue , defaultHashCap )
@@ -186,6 +196,7 @@ func (tb *LTable) RawSetString(key string, value LValue) {
186
196
}
187
197
}
188
198
199
+ // RawSetH sets a given LValue to a given index without the __newindex metamethod.
189
200
func (tb * LTable ) RawSetH (key LValue , value LValue ) {
190
201
if s , ok := key .(LString ); ok {
191
202
tb .RawSetString (string (s ), value )
@@ -202,6 +213,7 @@ func (tb *LTable) RawSetH(key LValue, value LValue) {
202
213
}
203
214
}
204
215
216
+ // RawGet returns an LValue associated with a given key without __index metamethod.
205
217
func (tb * LTable ) RawGet (key LValue ) LValue {
206
218
switch v := key .(type ) {
207
219
case LNumber :
@@ -233,6 +245,7 @@ func (tb *LTable) RawGet(key LValue) LValue {
233
245
return LNil
234
246
}
235
247
248
+ // RawGetInt returns an LValue at position `key` without __index metamethod.
236
249
func (tb * LTable ) RawGetInt (key int ) LValue {
237
250
if tb .array == nil {
238
251
return LNil
@@ -244,6 +257,7 @@ func (tb *LTable) RawGetInt(key int) LValue {
244
257
return tb .array [index ]
245
258
}
246
259
260
+ // RawGet returns an LValue associated with a given key without __index metamethod.
247
261
func (tb * LTable ) RawGetH (key LValue ) LValue {
248
262
if s , sok := key .(LString ); sok {
249
263
if tb .strdict == nil {
@@ -263,6 +277,7 @@ func (tb *LTable) RawGetH(key LValue) LValue {
263
277
return LNil
264
278
}
265
279
280
+ // RawGetString returns an LValue associated with a given key without __index metamethod.
266
281
func (tb * LTable ) RawGetString (key string ) LValue {
267
282
if tb .strdict == nil {
268
283
return LNil
@@ -273,6 +288,7 @@ func (tb *LTable) RawGetString(key string) LValue {
273
288
return LNil
274
289
}
275
290
291
+ // ForEach iterates over this table of elements, yielding each in turn to a given function.
276
292
func (tb * LTable ) ForEach (cb func (LValue , LValue )) {
277
293
if tb .array != nil {
278
294
for i , v := range tb .array {
@@ -297,6 +313,7 @@ func (tb *LTable) ForEach(cb func(LValue, LValue)) {
297
313
}
298
314
}
299
315
316
+ // This function is equivalent to lua_next ( http://www.lua.org/manual/5.1/manual.html#lua_next ).
300
317
func (tb * LTable ) Next (key LValue ) (LValue , LValue ) {
301
318
// TODO: inefficient way
302
319
if key == LNil {
0 commit comments