def _fixStack(a: int, vm: LuaVM): x = vm.ToInteger(-1) vm.Pop(1) vm.CheckStack(x - a) for i in range(a, x): vm.PushValue(i) vm.Rotate(vm.RegisterCount() + 1, x - a)
def setlist(self, vm: LuaVM): a, b, c = self.getAbc() a += 1 if c > 0: c -= 1 else: c = Instruction(vm.Fetch()).getAx() bisZero = b is 0 if bisZero: b = (vm.ToInteger(-1)) - a - 1 vm.Pop(1) vm.CheckStack(1) index = c * LuaTable.LFIELDS_PER_FLUSH for i in range(1, b + 1): index += 1 vm.PushValue(a + i) vm.SetI(a, index) if bisZero: for i in range(vm.RegisterCount() + 1, vm.GetTop() + 1): index += 1 vm.PushValue(i) vm.SetI(a, index) vm.SetTop(vm.RegisterCount())
def _popResults(self, a: int, c: int, vm: LuaVM): if c is 1: pass elif c > 1: for i in range(a + c - 2, a - 1, -1): vm.Replace(i) else: vm.CheckStack(1) vm.PushInteger(a)
def _pushFuncAndArgs(self, a: int, b: int, vm: LuaVM) -> int: if b >= 1: vm.CheckStack(b) for i in range(a, a + b): vm.PushValue(i) return b - 1 else: self._fixStack(a, vm) return vm.GetTop() - vm.RegisterCount() - 1
def _return(self, vm: LuaVM): a, b, _ = self.getAbc() a += 1 if b is 1: pass elif b > 1: vm.CheckStack(b - 1) for i in range(a, a + b - 1): vm.PushValue(i) else: self._fixStack(a, vm)