Remove removes from this table the element at a given position.
(pos int)
| 117 | |
| 118 | // Remove removes from this table the element at a given position. |
| 119 | func (tb *LTable) Remove(pos int) LValue { |
| 120 | if tb.array == nil { |
| 121 | return LNil |
| 122 | } |
| 123 | larray := len(tb.array) |
| 124 | if larray == 0 { |
| 125 | return LNil |
| 126 | } |
| 127 | i := pos - 1 |
| 128 | oldval := LNil |
| 129 | switch { |
| 130 | case i >= larray: |
| 131 | // nothing to do |
| 132 | case i == larray-1 || i < 0: |
| 133 | oldval = tb.array[larray-1] |
| 134 | tb.array = tb.array[:larray-1] |
| 135 | default: |
| 136 | oldval = tb.array[i] |
| 137 | copy(tb.array[i:], tb.array[i+1:]) |
| 138 | tb.array[larray-1] = nil |
| 139 | tb.array = tb.array[:larray-1] |
| 140 | } |
| 141 | return oldval |
| 142 | } |
| 143 | |
| 144 | // RawSet sets a given LValue to a given index without the __newindex metamethod. |
| 145 | // It is recommended to use `RawSetString` or `RawSetInt` for performance |
no outgoing calls