RawSetInt sets a given LValue at a position `key` without the __newindex metamethod.
(key int, value LValue)
| 176 | |
| 177 | // RawSetInt sets a given LValue at a position `key` without the __newindex metamethod. |
| 178 | func (tb *LTable) RawSetInt(key int, value LValue) { |
| 179 | if key < 1 || key >= MaxArrayIndex { |
| 180 | tb.RawSetH(LNumber(key), value) |
| 181 | return |
| 182 | } |
| 183 | if tb.array == nil { |
| 184 | tb.array = make([]LValue, 0, 32) |
| 185 | } |
| 186 | index := key - 1 |
| 187 | alen := len(tb.array) |
| 188 | switch { |
| 189 | case index == alen: |
| 190 | tb.array = append(tb.array, value) |
| 191 | case index > alen: |
| 192 | for i := 0; i < (index - alen); i++ { |
| 193 | tb.array = append(tb.array, LNil) |
| 194 | } |
| 195 | tb.array = append(tb.array, value) |
| 196 | case index < alen: |
| 197 | tb.array[index] = value |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | // RawSetString sets a given LValue to a given string index without the __newindex metamethod. |
| 202 | func (tb *LTable) RawSetString(key string, value LValue) { |