MCPcopy Index your code
hub / github.com/yuin/gopher-lua / Next

Method Next

table.go:351–387  ·  view source on GitHub ↗

This function is equivalent to lua_next ( http://www.lua.org/manual/5.1/manual.html#lua_next ).

(key LValue)

Source from the content-addressed store, hash-verified

349
350// This function is equivalent to lua_next ( http://www.lua.org/manual/5.1/manual.html#lua_next ).
351func (tb *LTable) Next(key LValue) (LValue, LValue) {
352 init := false
353 if key == LNil {
354 key = LNumber(0)
355 init = true
356 }
357
358 if init || key != LNumber(0) {
359 if kv, ok := key.(LNumber); ok && isInteger(kv) && int(kv) >= 0 && kv < LNumber(MaxArrayIndex) {
360 index := int(kv)
361 if tb.array != nil {
362 for ; index < len(tb.array); index++ {
363 if v := tb.array[index]; v != LNil {
364 return LNumber(index + 1), v
365 }
366 }
367 }
368 if tb.array == nil || index == len(tb.array) {
369 if (tb.dict == nil || len(tb.dict) == 0) && (tb.strdict == nil || len(tb.strdict) == 0) {
370 return LNil, LNil
371 }
372 key = tb.keys[0]
373 if v := tb.RawGetH(key); v != LNil {
374 return key, v
375 }
376 }
377 }
378 }
379
380 for i := tb.k2i[key] + 1; i < len(tb.keys); i++ {
381 key := tb.keys[i]
382 if v := tb.RawGetH(key); v != LNil {
383 return key, v
384 }
385 }
386 return LNil, LNil
387}

Callers 3

baseNextFunction · 0.45
pairsauxFunction · 0.45
strGsubStrFunction · 0.45

Calls 3

RawGetHMethod · 0.95
LNumberTypeAlias · 0.85
isIntegerFunction · 0.85

Tested by

no test coverage detected