✓ Accepted answer
You had the right idea with the first example, but you'd just be storing variables you haven't defined yet. You should be defining the functions first, then using them as elements to a table. Functions can be stored inside tables just as any other data type. Here's a few examples marking the similarities:
Creating a new index
local t = {}
t.x = 1
t.y = "string"
t.z = function()
print("Hello world")
end
t.z()
Would also be the same as:
local t = {}
local function x()
print("Function x")
end
t.x = x
t.y = x
t.z = x
Creating a method
local t = {}
function t:method()
print("Hello world")
end
t:method()
Initial storage
local t = {
x = function()
print("x")
end;
y = function()
print("y")
end;
x2 = "hello";
y2 = 100;
}
local t = {
function()
print("Anonymous")
end;
"hello";
100;
}
So as demonstrated, it's the same as storing any other ordinary data type (strings, numbers, bools, etc). The only exception is creating the function as a method, which is a discussion for a different topic. Anyway, hope this cleared things up. Let me know if you have any questions.
1 comment
note, func1, func2 etc are just names. they can be anything, same goes for a,b,c.