(method string, isZero bool, iter Function)
| 19 | } |
| 20 | |
| 21 | func 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 | |
| 40 | func intPairs(l *State) int { |
| 41 | i := CheckInteger(l, 2) |
no test coverage detected