Earlier, I was typing code in this GUI I made (that uses vLua) and I tried to iterate over a table;
for i,v in {"example","table"} do
print(v)
end
>example, table
But, if I put it through vLua (vLua 5.1 (improved VM) - Roblox), it threw the error ‘attempt to call table value’, so I had to instead do this;
for i,v in pairs({"example","table"}) do
print(v)
end
Have i,v pairs been updated, does vLua just not support doing that? I remember I always used to use for i,v in pairs(<table>) do instead of just putting for i,v in <table> do, but it doesn’t seem to work in vLua.
Although I am not familiar with vLua, I do know that Roblox Luau was updated to support “Generalized Iteration” within the past half a year, which essentially means that you can omit / not include the pairs or ipairs and, as far as I’m aware, it’ll iterate over the table with ipairs by default before using pairs.
That means that the following example would work just fine, even without including pairs or ipairs:
local exampleTable = {1, 2, 3}
local exampleTable2 = {
["pumpkin pie"] = "yummy",
["object"] = nil,
[100] = "random number"
}
for i, v in exampleTable do
print(v)
end
for i, v in exampleTable2 do
print(i, v)
end
I’m not super knowledgeable on the technical details behind it, so here are some relevant resources that may be more insightful: