1. The first sentence states "Adding an element to an array is as simple as associating the value to the next integer key in sequence" followed by example tbl[#tbl] = "new element"

    It should be tbl[#tbl + 1] = "new element"

    The first sentence states "Adding an element to an array is as simple as associating the value to the next integer key in sequence" followed by example tbl[#tbl] = "new element"

    It should be tbl[#tbl + 1] = "new element"

    I came here to mention this also, and was'nt sure I could just add the +1

    thanks for pointing it out. :)

    Thanks for the note. I'll add this to the errata.

    It actually may have been on the errata at one point, but we had to restore the site from backups a while back (no) thanks to our previous host.

    Which is actually more efficient?

    tbl[#tbl + 1] = "new element"

    or

    table.insert(tbl, "new element")

    or is it pretty much a wash and just a matter of style?

    -- Matthew

    The fastest is the following:

    local c = #tbl

    tbl[c] = newValue;

    c = c + 1

    But you should not be worry about things like that at this stage.  Premature optimization is the root of all evil and it's much more important that your code works correctly before nit-picking =).

    No worries on that part.  There's not much optimizing happening here yet.  It was just a matter of curiousity more than anything.  I couldn't agree more to your statement about premature optimization.  Thank you for the information.

    -- Matthew