lua-users home
lua-l archive

Newbie: ipairs() for tables with non integer keys

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,

Does ipairs() work only with integer keys? if so why?

student = {}
student.name = "Test"
student.age = 25

for i,v in ipairs(student) do -- A
print(i,"=>",v)
end

test_arr = {4,5,6}
for i,v in ipairs(test_arr) do -- B
print(i,"=>",v)
end

#########################
---------- Run ----------
1 => 4
2 => 5
3 => 6

Output completed (0 sec consumed) - Normal Termination

I expected that the for loop at A to print something like
"name" => "Test"
"age" => 25


Cheers,
GG

AltStyle によって変換されたページ (->オリジナル) /