lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


If `luac -l` is used, it is possible to show that tables are allocated with more space instead of having to allocate more space while running. I should go probably see if my programs and stuff do this.

On Mon, Feb 20, 2017, 02:10 Daurnimator <quae@daurnimator.com> wrote:
On 20 February 2017 at 19:00, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> Would you occasionally code
>
>     tbl = { [1]="abc", [2]="def", k1=nil, k2=nil}
>
> rather than
>
>     tbl = {"abc","def"}
>
> deliberately?
>

Yes; this A) is a form of documentation that shows the
expected/allowed/future members of your table; and B) will preallocate
a table that will be sure to fit all the members.

I often do it in my libraries. e.g.
https://github.com/daurnimator/lua-http/blob/6d79d1233077d9be54cf76686783044e1a17e0d1/http/h2_connection.lua#L151

--