diff --git a/README.md b/README.md index 5d2cc7c..201401e 100644 --- a/README.md +++ b/README.md @@ -71,8 +71,9 @@ R[5]: i ==== [[example.lua's pseudo-code]] ==== local tbl = {"He", "llo", " ", "Wo", "rld", "!", } +local str = "" for i = 1, #tbl, 1 do - local str = str .. tbl[i] + str = str .. tbl[i] end print(str) diff --git a/lparser.py b/lparser.py index 0e09990..793e407 100644 --- a/lparser.py +++ b/lparser.py @@ -207,7 +207,6 @@ class LuaDecomp: self.__endStatement() - # =====================================[[ Instructions ]]====================================== def __emitOperand(self, a: int, b: str, c: str, op: str) -> None: @@ -268,7 +267,7 @@ class LuaDecomp: tblOps = [Opcodes.LOADK, Opcodes.SETLIST] instr = self.__getNextInstr() - cachedRegs = self.top + cachedRegs = {} tbl = "{" while instr.opcode in tblOps: if instr.opcode == Opcodes.LOADK: # operate on registers @@ -278,6 +277,7 @@ class LuaDecomp: for i in range(numElems): tbl += "%s, " % cachedRegs[instr.A + i + 1] + del cachedRegs[instr.A + i + 1] self.pc += 1 instr = self.__getNextInstr() @@ -289,6 +289,10 @@ class LuaDecomp: self.__setReg(indx, tbl, forceLocal=True) self.__endStatement() + # if we have leftovers... oops, set those + for i, v in cachedRegs.items(): + self.__setReg(i, v) + def parseInstr(self): instr = self.__getCurrInstr()