Skip to content

Commit

Permalink
Fixes #35
Browse files Browse the repository at this point in the history
  • Loading branch information
gnois committed Jul 28, 2017
1 parent 6dd6f8f commit 4c0b814
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lang/luacode-generator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ end

function ExpressionRule:Table(node)
local hash = { }
for i = 1, #node.keyvals do
local last = #node.keyvals
for i = 1, last do
local kv = node.keyvals[i]
local val = self:expr_emit(kv[1])
local key = kv[2]
Expand All @@ -171,7 +172,11 @@ function ExpressionRule:Table(node)
hash[i] = format("[%s] = %s", self:expr_emit(key), val)
end
else
hash[i] = format("%s", val)
if i == last and kv[1].bracketed then
hash[i] = format("(%s)", val)
else
hash[i] = format("%s", val)
end
end
end
local content = ""
Expand Down
18 changes: 18 additions & 0 deletions tests/table-8.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
local eq = function(n, t1, t2)
for i = 1, n do
if t1[i] ~= t2[i] then
local msg = "[" .. i .. "]: "
msg = msg .. (tostring(t1[i]) or "nil") .. " " .. (tostring(t2[i]) or "nil")
error(msg, 2)
end
end
end
local foo = function(...)
return ...
end
local triple, single = {2, 3, 4}, {2, nil, nil}
eq(4, {foo(2,3,4)}, triple)
eq(4, {(foo(2,3,4))}, single)
eq(6, {foo(2,3,4), 3, 4}, triple)
eq(6, {2, 3, (foo(4,5,6))}, triple)
eq(6, {2, 3, foo(4,5,6)}, {2, 3, 4, 5, 6})

0 comments on commit 4c0b814

Please sign in to comment.