def gettable(self, vm: LuaVM): a, b, c = self.getAbc() a += 1 b += 1 vm.GetRk(c) vm.GetTable(b) vm.Replace(a)
def gettabup(self, vm: LuaVM): a, b, c = self.getAbc() a += 1 b += 1 vm.GetRk(c) vm.GetTable(vm.LuaUpvalueIndex(b)) vm.Replace(a)
def self(self, vm: LuaVM): a, b, c = self.getAbc() a += 1 b += 1 vm.Copy(b, a + 1) vm.GetRk(c) vm.GetTable(b) vm.Replace(a)
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)
def tailCall(self, vm: LuaVM): a, b, _ = self.getAbc() a += 1 c = 0 nArgs = self._pushFuncAndArgs(a, b, vm) vm.Call(nArgs, c - 1) self._popResults(a, c, vm)
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 setupval(self, vm: LuaVM): a, b, _ = self.getAbc() a += 1 b += 1 vm.Copy(a, vm.LuaUpvalueIndex(b))
def settabup(self, vm: LuaVM): a, b, c = self.getAbc() a += 1 vm.GetRk(b) vm.GetRk(c) vm.SetTable(vm.LuaUpvalueIndex(a))
def vararg(self, vm: LuaVM): a, b, _ = self.getAbc() a += 1 if b is not 1: vm.LoadVararg(b - 1) self._popResults(a, b, vm)
def closure(self, vm: LuaVM): a, bx = self.getAbx() a += 1 vm.LoadProto(bx) vm.Replace(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 settable(self, vm: LuaVM): a, b, c = self.getAbc() a += 1 vm.GetRk(b) vm.GetRk(c) vm.SetTable(a)
def newtable(self, vm: LuaVM): a, b, c = self.getAbc() a += 1 vm.CreateTable(FbToInt(b), FbToInt(c)) vm.Replace(a)