Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

Lua actually has arbitrary indexing, it's just that some iterator functions in the standard library assume arrays begin at 1.


It does and doesn't. You can have any arbitrary index, but that changes the table from being an array to being both an array and a dictionary, some real weird Frankenstein stuff


> but that changes the table from being an array to being both an array and a dictionary

You're confusing the definition of the language with the implementation. In implementation you're right, most runtimes will treat arrays starting at 1 as a special case and optimize that access. The language itself doesn't make that distinction though. Here an array is simply any table indexed by integers. The documentation states it's thusly:

    You can start an array at index 0, 1, or any other value




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: