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

Method Remove

table.go:119–142  ·  view source on GitHub ↗

Remove removes from this table the element at a given position.

(pos int)

Source from the content-addressed store, hash-verified

117
118// Remove removes from this table the element at a given position.
119func (tb *LTable) Remove(pos int) LValue {
120 if tb.array == nil {
121 return LNil
122 }
123 larray := len(tb.array)
124 if larray == 0 {
125 return LNil
126 }
127 i := pos - 1
128 oldval := LNil
129 switch {
130 case i >= larray:
131 // nothing to do
132 case i == larray-1 || i < 0:
133 oldval = tb.array[larray-1]
134 tb.array = tb.array[:larray-1]
135 default:
136 oldval = tb.array[i]
137 copy(tb.array[i:], tb.array[i+1:])
138 tb.array[larray-1] = nil
139 tb.array = tb.array[:larray-1]
140 }
141 return oldval
142}
143
144// RawSet sets a given LValue to a given index without the __newindex metamethod.
145// It is recommended to use `RawSetString` or `RawSetInt` for performance

Callers 7

osRemoveFunction · 0.45
osTmpnameFunction · 0.45
TestTableRemoveFunction · 0.45
TestLoadFileForShebangFunction · 0.45
TestLoadFileForEmptyFileFunction · 0.45
tableRemoveFunction · 0.45
TestRemoveFunction · 0.45

Calls

no outgoing calls

Tested by 4

TestTableRemoveFunction · 0.36
TestLoadFileForShebangFunction · 0.36
TestLoadFileForEmptyFileFunction · 0.36
TestRemoveFunction · 0.36