[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua 5.2 wish item: Splicing
- From: Rici Lake <lua@...>
- Date: Thu, 8 Feb 2007 14:32:03 -0500
On 8-Feb-07, at 2:09 PM, Rici Lake wrote:
There are a couple of other minor tweaks which need doing.
OK, updated.
I added this file as test/newtable.lua:
-- Tests for extended table constructor syntax
function t(name)
local function f(k, ...)
if k == 0 then
return ...
else
return f(k-1, name..tostring(k), ...)
end
end
return f
end
foo = t"foo" bar = t"bar" glitch = t"glitch"
function vals(u, t)
for k, v in pairs(t) do u[#u+1] = tostring(k).."="..tostring(v) end
return u
end
function show(t) return table.concat(vals({}, t), " ") end
print(show{foo(3); bar(2); glitch(5)})
-- should print:
-- 1=foo1 2=foo2 3=foo3 4=bar1 5=bar2 6=glitch1 7=glitch2 8=glitch3
-- 9=glitch4 10=glitch5
print(show{foo(3); bar(2), glitch(5)})
-- should print:
-- 1=foo1 2=foo2 3=foo3 4=bar1 5=glitch1 6=glitch2 7=glitch3 8=glitch4
-- 9=glitch5
-- print(show{foo(3); bar(2),, glitch(5)})
-- should be a syntax error: unexpected symbol near ','
print(show{foo(3); bar(2), glitch(5),})
-- should print:
-- 1=foo1 2=foo2 3=foo3 4=bar1 5=glitch1
print(show{foo(3); bar(2), (glitch(5))})
-- should print:
-- 1=foo1 2=foo2 3=foo3 4=bar1 5=glitch1
print(show{foo(3); bar(2); glitch(5); n = 10})
-- should print:
-- 1=foo1 2=foo2 3=foo3 4=bar1 5=bar2 6=glitch1 7=glitch2 8=glitch3
-- 9=glitch4 10=glitch5 n=10
print(show{foo(3); bar(2); glitch(5), n = 10})
-- should print:
-- 1=foo1 2=foo2 3=foo3 4=bar1 5=bar2 6=glitch1 n=10