MCPcopy Index your code
hub / github.com/Shopify/go-lua / next

Method next

tables.go:224–263  ·  view source on GitHub ↗
(t *table, key int)

Source from the content-addressed store, hash-verified

222}
223
224func (l *State) next(t *table, key int) bool {
225 i, k := 0, l.stack[key]
226 if k == nil { // first iteration
227 } else if i = arrayIndex(k); 0 < i && i <= len(t.array) {
228 k = nil
229 } else if _, ok := t.hash[k]; !ok {
230 l.runtimeError("invalid key to 'next'") // key not found
231 } else {
232 i = len(t.array)
233 }
234 for ; i < len(t.array); i++ {
235 if t.array[i] != nil {
236 l.stack[key] = float64(i + 1)
237 l.stack[key+1] = t.array[i]
238 return true
239 }
240 }
241 if t.iterationKeys == nil {
242 j, keys := 0, make([]value, len(t.hash))
243 for hk := range t.hash {
244 keys[j] = hk
245 j++
246 }
247 t.iterationKeys = keys
248 }
249 found := k == nil
250 for i, hk := range t.iterationKeys {
251 if hk == nil { // skip deleted key
252 } else if _, present := t.hash[hk]; !present {
253 t.iterationKeys[i] = nil // mark key as deleted
254 } else if found {
255 l.stack[key] = hk
256 l.stack[key+1] = t.hash[hk]
257 return true
258 } else if l.equalObjects(hk, k) {
259 found = true
260 }
261 }
262 return false // no more elements
263}

Callers 15

NextMethod · 0.95
checkNameMethod · 0.45
checkNextMethod · 0.45
functionArgumentsMethod · 0.45
primaryExpressionMethod · 0.45
suffixedExpressionMethod · 0.45
simpleExpressionMethod · 0.45
subExpressionMethod · 0.45
fieldSelectorMethod · 0.45
indexMethod · 0.45
forStatementMethod · 0.45
testThenBlockMethod · 0.45

Calls 3

runtimeErrorMethod · 0.95
equalObjectsMethod · 0.95
arrayIndexFunction · 0.85

Tested by

no test coverage detected