Reputation: 195
i am not able to handle table which is return by a function.can any one help me on this ?
local grades = { Mary = "100", Teacher="100",'4','6'}
print "Printing grades!"
grades.joe = "10"
grades_copy = grades
for k, v in ipairs(grades) do
-- print "Grade:"
-- print(k, v)
end
function returntable()
tablein = grades
return 'hello'
end
grades_copy_table = returntable
--print(grades_copy_table)
In that above program i want to access the table elements through that function " returntable" which return table.
Upvotes: 5
Views: 8123
Reputation: 122373
In Lua, functions are first-class values.
grades_copy_table = returntable
Here you are assigning grades_copy_table
the function returntable
itself, not its return value. You need to call that function and assign the returned value:
grades_copy_table = returntable()
Upvotes: 5