table.foreach is actually deprecated. You can exactly duplicate its functionality with this:
for k,v in pairs(t) do
makeVars(k, v)
end
And when you're at that point, you may as well do this:
local newtable = {}
for k,v in pairs(t) do
for key, value in string.gmatch(v, "(.+)=(.+)") do
newtable[key] = value
end
end
One final note: When your table has ascending numeric keys, as yours does in your first post, you might want to consider using ipairs() instead. (The old-style equivalent would be table.foreachi; note the 'i')
local newtable = {}
for k,v in ipairs(t) do
for key, value in string.gmatch(v, "(.+)=(.+)") do
newtable[key] = value
end
end
ipairs() just goes over the table items in order (i.e. t[1], t[2], t[3], etc.), and excludes non-number keys. |