Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
(1 edit)

Creating and returning a table with attributes is no problem.

function make()
    return { a=1, b=2 }
end 

Remember to assign it to a variable.

t = make()

Accessing those attributes is easy.

result = t.a + t.b

When you say t.a you're really saying the string key 'a', so it's equivalent to t['a'].

In Lua, you can also index by number (e.g. using tables like arrays, full or sparse) or by boolean (true or false). So t[1] or t[3.14159] or t[true] or t[false].

You can also index by table or by function, in which case Lua uses the identity of the table or function (so each is unique, even if they have the same contents). You can do t[make] or even t[t].

The only thing you cannot index by is nil. That is illegal.