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

后端 未结 8 2143
情歌与酒
情歌与酒 2020-12-12 18:34

I don\'t understand the rationale behind the decision of this part of Lua. Why does indexing start at 1? I have read (as many others did) this great paper. It seems to me a

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-12 19:04

    The real reason is that the language is an implementation of the definition in a law of Portugal and the major development centre was in Brazil and their preference is to avoid the use of zero or empty or nothing as an index or subscript. However the language does permit the use of a start index other than 1 in a table creating function in some versions.

提交回复
热议问题