RawSet sets a given LValue to a given index without the __newindex metamethod. It is recommended to use `RawSetString` or `RawSetInt` for performance if you already know the given LValue is a string or number.
(key LValue, value LValue)
| 145 | // It is recommended to use `RawSetString` or `RawSetInt` for performance |
| 146 | // if you already know the given LValue is a string or number. |
| 147 | func (tb *LTable) RawSet(key LValue, value LValue) { |
| 148 | switch v := key.(type) { |
| 149 | case LNumber: |
| 150 | if isArrayKey(v) { |
| 151 | if tb.array == nil { |
| 152 | tb.array = make([]LValue, 0, defaultArrayCap) |
| 153 | } |
| 154 | index := int(v) - 1 |
| 155 | alen := len(tb.array) |
| 156 | switch { |
| 157 | case index == alen: |
| 158 | tb.array = append(tb.array, value) |
| 159 | case index > alen: |
| 160 | for i := 0; i < (index - alen); i++ { |
| 161 | tb.array = append(tb.array, LNil) |
| 162 | } |
| 163 | tb.array = append(tb.array, value) |
| 164 | case index < alen: |
| 165 | tb.array[index] = value |
| 166 | } |
| 167 | return |
| 168 | } |
| 169 | case LString: |
| 170 | tb.RawSetString(string(v), value) |
| 171 | return |
| 172 | } |
| 173 | |
| 174 | tb.RawSetH(key, value) |
| 175 | } |
| 176 | |
| 177 | // RawSetInt sets a given LValue at a position `key` without the __newindex metamethod. |
| 178 | func (tb *LTable) RawSetInt(key int, value LValue) { |
no test coverage detected