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

Method Insert

table.go:87–103  ·  view source on GitHub ↗

Insert inserts a given LValue at position `i` in this table.

(i int, value LValue)

Source from the content-addressed store, hash-verified

85
86// Insert inserts a given LValue at position `i` in this table.
87func (tb *LTable) Insert(i int, value LValue) {
88 if tb.array == nil {
89 tb.array = make([]LValue, 0, defaultArrayCap)
90 }
91 if i > len(tb.array) {
92 tb.RawSetInt(i, value)
93 return
94 }
95 if i <= 0 {
96 tb.RawSet(LNumber(i), value)
97 return
98 }
99 i -= 1
100 tb.array = append(tb.array, LNil)
101 copy(tb.array[i+1:], tb.array[i:])
102 tb.array[i] = value
103}
104
105// MaxN returns a maximum number key that nil value does not exist before it.
106func (tb *LTable) MaxN() int {

Callers 7

TestTableInsertFunction · 0.45
basePCallFunction · 0.45
baseXPCallFunction · 0.45
initFunction · 0.45
wrapauxFunction · 0.45
tableInsertFunction · 0.45
initFunction · 0.45

Calls 3

RawSetIntMethod · 0.95
RawSetMethod · 0.95
LNumberTypeAlias · 0.85

Tested by 1

TestTableInsertFunction · 0.36