Skip to content

Commit

Permalink
fixed enumerate not working with list and improved list comp
Browse files Browse the repository at this point in the history
  • Loading branch information
Arif812 committed Apr 28, 2024
1 parent 69876de commit f7f9ce3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test.py
22 changes: 12 additions & 10 deletions src/libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,16 +311,18 @@
deltaattr = function (object, attribute) -- delattr
object[attribute] = nil
end
enumerate = function (iterable) -- enumerate
local i = 0
return function()
i = i + 1
local value = iterable[i]
if value ~= nil then
return i, value
end
end
end
enumerate = function (t)
local i = 0
return function()
i = i + 1
local value = t(nil, i)
if value ~= nil then
return i, value
end
end
end
bytearray = function (arg) -- bytearray
if type(arg) == "string" then
local bytes = {}
Expand Down
3 changes: 1 addition & 2 deletions src/nodevisitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,8 +890,7 @@ def visit_ListComp(self, node):
self.emit(line)
ends_count += 1

line = "result.append({})"
line = line.format(self.visit_all(node.elt, inline=True))
line = f"table.insert(result._data," + "{" + {self.visit_all(node.elt, inline=True)} + "}"
self.emit(line)

self.emit(" ".join(["end"] * ends_count))
Expand Down

0 comments on commit f7f9ce3

Please sign in to comment.