MCPcopy Index your code
hub / github.com/yuin/gopher-lua / RawSet

Method RawSet

table.go:147–175  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

145// It is recommended to use `RawSetString` or `RawSetInt` for performance
146// if you already know the given LValue is a string or number.
147func (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.
178func (tb *LTable) RawSetInt(key int, value LValue) {

Callers 3

InsertMethod · 0.95
baseRawSetFunction · 0.45
mainAuxFunction · 0.45

Calls 3

RawSetStringMethod · 0.95
RawSetHMethod · 0.95
isArrayKeyFunction · 0.85

Tested by

no test coverage detected