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

后端 未结 8 2142
情歌与酒
情歌与酒 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 18:59

    It makes sense to everyone, that if

    table = {}
    

    table is empty. So, when

    table == {something}
    

    The table contains something so what it contains is index 1 in table, if you know what I mean.

    What I meant is that table[0] exists, and its table = {}, which is empty, now a programmer won't call a empty table, it sets them, and then fills it, it will be useless to find an empty table every time you want to call it, so it's simpler to just create an empty table.

    My English won't get better and that's my best grammar. If you don't like it, you're free to not keep reading it, but giving -rep for someone trying to help makes people not want to help at all, especially for something like grammar. I'm a man of numbers and vars, not grammar. Sorry.

提交回复
热议问题