tech-userlevel archive

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

Re: Lua in-kernel (lbuf library)



On Wed, Oct 16, 2013 at 3:50 AM, Marc Balmer <marc%msys.ch@localhost> wrote:
> Am 15.10.13 23:01, schrieb Lourival Vieira Neto:
>
> [...]
>
>>> Also, having to switch mentally between zero-based arrays in the kernel C
>>> code and 1-based arrays in the Lua code make my head ache.
>>
>> It's something that doesn't bug me so much.. But, if necessary it
>> could be changed to 0-based in this userdata.
>
> In C an array index is actually an offset from the top, so 0 is the
> natural way to denote element nr. 1 in C.  In Lua, a numeric array index
> is not an offset, but the ordinal array position.  So 1 is the natural
> way to denote the first element.
>
> Strictly speaking, it's actually C that is weird:  Index n denotes array
> element n + 1...
>
> Following the principle of least astonishment, I would not recommend
> starting to do 0 based stuff in Lua, a Lua programmer certainly expects
> things to start at 1.
>
> [...]

Indeed.
-- 
Lourival Vieira Neto


Home | Main Index | Thread Index | Old Index