ANNOUNCEMENT: Live Wireshark University & Allegro Packets online APAC Wireshark Training Session
July 17th, 2024 | 10:00am-11:55am SGT (UTC+8) | Online

Wireshark-dev: Re: [Wireshark-dev] accessing multiple occurrences of the same field with lua

From: Hadriel Kaplan <HKaplan@xxxxxxxxxxxxxx>
Date: Sat, 9 Mar 2013 15:09:51 +0000
On Mar 9, 2013, at 3:41 AM, Cristian Constantin <const.crist@xxxxxxxxxxxxxx> wrote:
> cristian: if I need tag as a number I should use:
> 
> tonumber (tostring (tag))
> 
> right?
> 

You can do it that way - but looking at the C-code it looks like you can also just do this:
    local myval = tag.value
or this:
    local myval = tag()

In both of those cases 'myval' will be a Lua number of the tag value as well, because a FieldInfo object for a "m3ua.parameter_length" field value is a FT_UINT16 type internally, so getting its value should get you a Lua number.  Any FieldInfo of an internal type FT_FLOAT/DOUBLE/UINTx/INTx will give a Lua number when its value is retrieved. (except FT_UINT64/FT_INT64)  Or at least the code looks like it will do that, I haven't tried it myself.

-hadriel