5

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.

1 Answer 1

5

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()
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.