Insert inserts a given LValue at position `i` in this table.
(i int, value LValue)
| 85 | |
| 86 | // Insert inserts a given LValue at position `i` in this table. |
| 87 | func (tb *LTable) Insert(i int, value LValue) { |
| 88 | if tb.array == nil { |
| 89 | tb.array = make([]LValue, 0, defaultArrayCap) |
| 90 | } |
| 91 | if i > len(tb.array) { |
| 92 | tb.RawSetInt(i, value) |
| 93 | return |
| 94 | } |
| 95 | if i <= 0 { |
| 96 | tb.RawSet(LNumber(i), value) |
| 97 | return |
| 98 | } |
| 99 | i -= 1 |
| 100 | tb.array = append(tb.array, LNil) |
| 101 | copy(tb.array[i+1:], tb.array[i:]) |
| 102 | tb.array[i] = value |
| 103 | } |
| 104 | |
| 105 | // MaxN returns a maximum number key that nil value does not exist before it. |
| 106 | func (tb *LTable) MaxN() int { |