local function foo(...: {string:number}) -- number values in the hash part of the table
local t = {...}
local sum = 0.0
for i = 1, #t do
for _, v in pairs(t[i]) do
sum = sum + v
end
end
print(sum)
end
foo({ a = 1 }) --> 1.0
foo({ a = 1, b = 2 }) --> 3.0
foo({ a = 1 }, { a = 2 }) --> 3.0
foo({ a = 1 }, { b = 2 }) --> 3.0
but with the type {integer|string:number}, errors come when more than one table
local function foo(...: {integer|string:number}) -- number values in the array part and the hash part of the table
local t = {...}
local sum = 0.0
for i = 1, #t do
for _, v in pairs(t[i]) do
sum = sum + v
end
end
print(sum)
end
foo({ 42.0, a = 1 }) --> 43.0
foo({ 42.0, a = 1, b = 2 }) --> 45.0
foo({ 42.0, a = 1 }, { 42.0, a = 2 }) -- ERROR: argument 2: can't match a record to a map with non-string keys
foo({ 42.0, a = 1 }, { 42.0, b = 2 }) -- ERROR: argument 2: can't match a record to a map with non-string keys
foo({ a = 1 }, { a = 2 }) -- ERROR: argument 2: can't match a record to a map with non-string keys
foo({ a = 1 }, { b = 2 }) -- ERROR: argument 2: can't match a record to a map with non-string keys
first, with the type
{string:number}
, all is finebut with the type
{integer|string:number}
, errors come when more than one table