I want to loop through a table that looks like this
function add(t, k, v, ...)
if k ~= nil then
t[k] = v
t[#t+1] = k
return add(t, ...)
end
return t
end
my_table = add({ }, "a", 5, "b", 4, "c", 3)
for i,k in ipairs(my_table) do
local v = my_table[k]
print(k, v)
end
Result:
a - 5
b - 4
c - 3
But I want to be able to loop through the table using the index, the key, and the value, so it looks like this:
1 - a - 5
2 - b - 4
3 - c - 3
Is this possible in Lua?