Why do Lua arrays(tables) start at 1 instead of 0?

Lua is descended from Sol, a language designed for petroleum engineers with no formal training in computer programming. People not trained in computing think it is damned weird to start counting at zero. By adopting 1-based array and string indexing, the Lua designers avoided confounding the expectations of their first clients and sponsors.

Although I too found them weird at the beginning, I have learned to love 0-based arrays. But I get by OK with Lua’s 1-based arrays, especially by
using Lua’s generic for loop and the ipairs operator—I can usually avoid worrying about just how arrays are indexed.

Leave a Comment