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

Function pairs

base.go:21–38  ·  view source on GitHub ↗
(method string, isZero bool, iter Function)

Source from the content-addressed store, hash-verified

19}
20
21func pairs(method string, isZero bool, iter Function) Function {
22 return func(l *State) int {
23 if hasMetamethod := MetaField(l, 1, method); !hasMetamethod {
24 CheckType(l, 1, TypeTable) // argument must be a table
25 l.PushGoFunction(iter) // will return generator,
26 l.PushValue(1) // state,
27 if isZero { // and initial value
28 l.PushInteger(0)
29 } else {
30 l.PushNil()
31 }
32 } else {
33 l.PushValue(1) // argument 'self' to metamethod
34 l.Call(1, 3) // get 3 values from metamethod
35 }
36 return 3
37 }
38}
39
40func intPairs(l *State) int {
41 i := CheckInteger(l, 2)

Callers 1

base.goFile · 0.85

Calls 7

MetaFieldFunction · 0.85
CheckTypeFunction · 0.85
PushGoFunctionMethod · 0.80
PushValueMethod · 0.80
PushIntegerMethod · 0.80
PushNilMethod · 0.80
CallMethod · 0.80

Tested by

no test coverage detected