SetTop accepts any index, or 0, and sets the stack top to index. If the new top is larger than the old one, then the new elements are filled with nil. If index is 0, then all stack elements are removed. If index is negative, the stack will be decremented by that much. If the decrement is larger tha
(index int)
| 554 | // |
| 555 | // http://www.lua.org/manual/5.2/manual.html#lua_settop |
| 556 | func (l *State) SetTop(index int) { |
| 557 | f := l.callInfo.function |
| 558 | if index >= 0 { |
| 559 | if apiCheck && index > l.stackLast-(f+1) { |
| 560 | panic("new top too large") |
| 561 | } |
| 562 | i := l.top |
| 563 | for l.top = f + 1 + index; i < l.top; i++ { |
| 564 | l.stack[i] = nil |
| 565 | } |
| 566 | } else { |
| 567 | if apiCheck && -(index+1) > l.top-(f+1) { |
| 568 | panic("invalid new top") |
| 569 | } |
| 570 | l.top += index + 1 // 'subtract' index (index is negative) |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | // Remove the element at the given valid index, shifting down the elements |
| 575 | // above index to fill the gap. This function cannot be called with a |
no outgoing calls