Search code examples
lualua-table

How do I append to a table in Lua


I'm trying to figure out the equivalent of:

foo = []
foo << "bar"
foo << "baz"

I don't want to have to come up with an incrementing index. Is there an easy way to do this?


Solution

  • You are looking for the insert function, found in the table section of the main library.

    foo = {}
    table.insert(foo, "bar")
    table.insert(foo, "baz")