tech-kern archive

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

Re: Lua in-kernel (lbuf library)



On Thu, Oct 24, 2013 at 5:41 AM, Marc Balmer <marc%msys.ch@localhost> wrote:
> Am 21.10.13 00:05, schrieb Christoph Badura:
>> On Tue, Oct 15, 2013 at 06:01:29PM -0300, Lourival Vieira Neto wrote:
>>>> 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.
>>
>> When you create your own data structures, I guess it is a wash.  You have
>> to adjust +/-1 in infrequent circumstances in either scenario.
>>
>> But in this case you are creating a special purpose language that operates
>> in universe of zero-based array.  And that's not only the kernel code.
>> Every Internet protocol specification that I remember is using zero-based
>> indexing.  For someone dealing with both sides (the world and your lua
>> library), it makes the difference between constantly having to be alert
>> to remember to do the offset adjustment.  That is a lot more mental work
>> for anyone working with this library.
>>
>> If you use 1-based indices talking to protocol people will be funny too:
>>
>> ``Anyone know why the flags in byte 6 of this packet are funny?''
>> ``Sure, that's most likely because the flags are in byte 5.''
>>
>> I think it is worth thinking hard about this.
>>
>> From a cursory reading of the Wireshark Lua API, it seems to me they are
>> using 0-based indices too.
>
> It probably depends whether you are access a Lua table (where you'd
> expect 1-based) or if you are accessin an in-kernel datastructure that
> is not strictly a Lua table.  If a Lua function is to mimick an existing
> C function, it might be better indeed to use 0-based access, to not
> confuse developers who are probably familiar with the corresponding C
> function.
>
> As this is mostly a matter of taste/source of confusion, it should be
> documented.  A man page for a Lua function that offers the same or
> similar functionality as a C function should state whether it's 0-based
> or 1-based, imo.

Indeed.

-- 
Lourival Vieira Neto


Home | Main Index | Thread Index | Old Index