Skip to content

Commit

Permalink
writer: fix tables with indices starting with 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrian Nord authored and Andrian Nord committed Jan 27, 2014
1 parent 949eca8 commit 9464a24
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions ljd/lua/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,20 @@ def visit_table_constructor(self, node):
all_records = nodes.RecordsList()
all_records.contents = array + records

while len(array) > 0:
if len(array) > 0:
first = array[0].value

if not isinstance(first, nodes.Primitive):
break

if first.type == nodes.Primitive.T_NIL:
all_records.contents.pop(0)

break

all_records.contents.pop(0)

if not isinstance(first, nodes.Primitive) \
or first.type != first.T_NIL:
record = nodes.TableRecord()
record.key = nodes.Constant()
record.key.type = nodes.Constant.T_INTEGER
record.key.value = 0
record.value = first

all_records.contents.insert(0, record)

self._visit(all_records)

Expand Down

0 comments on commit 9464a24

Please sign in to comment.