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

Method ForEach

table.go:326–348  ·  view source on GitHub ↗

ForEach iterates over this table of elements, yielding each in turn to a given function.

(cb func(LValue, LValue))

Source from the content-addressed store, hash-verified

324
325// ForEach iterates over this table of elements, yielding each in turn to a given function.
326func (tb *LTable) ForEach(cb func(LValue, LValue)) {
327 if tb.array != nil {
328 for i, v := range tb.array {
329 if v != LNil {
330 cb(LNumber(i+1), v)
331 }
332 }
333 }
334 if tb.strdict != nil {
335 for k, v := range tb.strdict {
336 if v != LNil {
337 cb(LString(k), v)
338 }
339 }
340 }
341 if tb.dict != nil {
342 for k, v := range tb.dict {
343 if v != LNil {
344 cb(k, v)
345 }
346 }
347 }
348}
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) {

Callers 3

TestTableForEachFunction · 0.45

Calls 2

LNumberTypeAlias · 0.85
LStringTypeAlias · 0.85

Tested by 3

TestTableForEachFunction · 0.36