MCPcopy Index your code
hub / github.com/Shopify/go-lua / put

Method put

tables.go:118–145  ·  view source on GitHub ↗
(l *State, k, v value)

Source from the content-addressed store, hash-verified

116}
117
118func (t *table) put(l *State, k, v value) {
119 switch k := k.(type) {
120 case nil:
121 l.runtimeError("table index is nil")
122 case float64:
123 if i := int(k); float64(i) == k {
124 t.putAtInt(i, v)
125 } else if math.IsNaN(k) {
126 l.runtimeError("table index is NaN")
127 } else if v == nil {
128 delete(t.hash, k)
129 } else {
130 t.addOrInsertHash(k, v)
131 }
132 case string:
133 if v == nil {
134 delete(t.hash, k)
135 } else {
136 t.addOrInsertHash(k, v)
137 }
138 default:
139 if v == nil {
140 delete(t.hash, k)
141 } else {
142 t.addOrInsertHash(k, v)
143 }
144 }
145}
146
147// OPT: tryPut is an optimized variant of the at/put pair used by setTableAt to avoid hashing the key twice.
148func (t *table) tryPut(l *State, k, v value) bool {

Callers 2

RawSetMethod · 0.80
setTableAtMethod · 0.80

Calls 3

putAtIntMethod · 0.95
addOrInsertHashMethod · 0.95
runtimeErrorMethod · 0.80

Tested by

no test coverage detected