aboutsummaryrefslogtreecommitdiffstats
path: root/epan/wslua
diff options
context:
space:
mode:
authorStig Bjørlykke <stig@bjorlykke.org>2016-12-17 10:08:54 +0100
committerStig Bjørlykke <stig@bjorlykke.org>2016-12-20 10:36:31 +0000
commitd4eeeaf6d463f930c89e9026b682339e1e114b34 (patch)
tree19c3f736edb85e2aa904aceb7e7da9c5257bf980 /epan/wslua
parentd9cc2b52260dac9830ac60239c4d80721df59b96 (diff)
Lua: Add unit names support.
Add support for using unit names in ProtoField integer types by using base.UNIT_STRING. Add unit name table argument in ProtoField.float() and ProtoField.double() (and made backward compatibility). The use of base.UNIT_STRING is not really the best API for adding unit names in Lua, but is the simples solution without adding new arguments to ProtoField. Change-Id: Ib5d064480cffd970a41db1764440642f6c593bb2 Reviewed-on: https://code.wireshark.org/review/19313 Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
Diffstat (limited to 'epan/wslua')
-rwxr-xr-xepan/wslua/make-init-lua.pl6
-rw-r--r--epan/wslua/wslua_proto_field.c231
2 files changed, 194 insertions, 43 deletions
diff --git a/epan/wslua/make-init-lua.pl b/epan/wslua/make-init-lua.pl
index f1b2e945f8..9c848048c1 100755
--- a/epan/wslua/make-init-lua.pl
+++ b/epan/wslua/make-init-lua.pl
@@ -184,6 +184,12 @@ while(<PROTO_H>) {
$bases_table .= "\t[\"$1\"] = $2,\n";
}
+ if (/^#define\s+BASE_(UNIT_STRING)[ ]*((0x)?[0-9]+) / ) {
+ # Handle BASE_UNIT_STRING as a valid base value in Lua
+ my $num = hex($2);
+ $bases_table .= "\t[\"$1\"] = $num,\n";
+ }
+
if (/^.define\s+PI_SEVERITY_MASK /) {
$in_severity = 1;
$skip_this = 1;
diff --git a/epan/wslua/wslua_proto_field.c b/epan/wslua/wslua_proto_field.c
index a8a5919d20..64c495e4c0 100644
--- a/epan/wslua/wslua_proto_field.c
+++ b/epan/wslua/wslua_proto_field.c
@@ -105,6 +105,7 @@ static const struct field_display_string_t base_displays[] = {
{"base.OCT", BASE_OCT},
{"base.DEC_HEX", BASE_DEC_HEX},
{"base.HEX_DEC", BASE_HEX_DEC},
+ {"base.UNIT_STRING", BASE_UNIT_STRING},
/* for FT_BOOLEAN, how wide the parent bitfield is */
{"8",8},
{"16",16},
@@ -301,6 +302,69 @@ static true_false_string* true_false_string_from_table(lua_State* L, int idx) {
return tfs;
}
+static unit_name_string* unit_name_string_from_table(lua_State* L, int idx) {
+ unit_name_string* units;
+
+ if (lua_isnil(L,idx)) {
+ return NULL;
+ } else if (!lua_istable(L,idx)) {
+ luaL_argerror(L,idx,"must be a table");
+ return NULL;
+ }
+
+ units = (unit_name_string *) g_malloc0(sizeof(unit_name_string));
+
+ lua_pushnil(L);
+
+ while (lua_next(L, idx)) {
+
+ if (! lua_isnumber(L,-2)) {
+ g_free(units->singular);
+ g_free(units->plural);
+ g_free(units);
+ luaL_argerror(L,idx,"All keys of a table used as unit name must be integers");
+ return NULL;
+ }
+
+ if (! lua_isstring(L,-1)) {
+ g_free(units->singular);
+ g_free(units->plural);
+ g_free(units);
+ luaL_argerror(L,idx,"All values of a table used as unit name must be strings");
+ return NULL;
+ }
+
+ /* Arrays in LUA start with index number 1 */
+ switch (lua_tointeger(L,-2)) {
+ case 1:
+ g_free((gchar *)units->singular);
+ units->singular = g_strdup(lua_tostring(L,-1));
+ break;
+ case 2:
+ g_free((gchar *)units->plural);
+ units->plural = g_strdup(lua_tostring(L,-1));
+ break;
+ default:
+ g_free(units->singular);
+ g_free(units->plural);
+ g_free(units);
+ luaL_argerror(L,idx,"The unit name table can have maximum two strings with key value 1 and 2");
+ return NULL;
+ }
+
+ lua_pop(L, 1);
+ }
+
+ if (!units->singular) {
+ g_free(units->plural);
+ g_free(units);
+ luaL_argerror(L,idx,"The unit name table must have a singular entry (key value 1)");
+ return NULL;
+ }
+
+ return units;
+}
+
static const gchar* check_field_name(lua_State* L, const int abbr_idx, const enum ftenum type) {
const gchar* abbr = luaL_checkstring(L,abbr_idx);
const header_field_info* hfinfo = NULL;
@@ -341,11 +405,12 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) {
`ftypes.SYSTEM_ID`, `ftypes.EUI64` or `ftypes.NONE`.
*/
#define WSLUA_OPTARG_ProtoField_new_VALUESTRING 4 /* A table containing the text that
- corresponds to the values, or one of `frametype.NONE`, `frametype.REQUEST`, `frametype.RESPONSE`,
+ corresponds to the values, or a table containing unit name for the values if base is
+ `base.UNIT_STRING`, or one of `frametype.NONE`, `frametype.REQUEST`, `frametype.RESPONSE`,
`frametype.ACK` or `frametype.DUP_ACK` if field type is ftypes.FRAMENUM. */
#define WSLUA_OPTARG_ProtoField_new_BASE 5 /* The representation, one of: `base.NONE`, `base.DEC`,
- `base.HEX`, `base.OCT`, `base.DEC_HEX`, or
- `base.HEX_DEC`. */
+ `base.HEX`, `base.OCT`, `base.DEC_HEX`,
+ `base.HEX_DEC` or `base.UNIT_STRING`. */
#define WSLUA_OPTARG_ProtoField_new_MASK 6 /* The bitmask to be used. */
#define WSLUA_OPTARG_ProtoField_new_DESCR 7 /* The description of the field. */
@@ -358,9 +423,11 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) {
value_string *vs32 = NULL;
val64_string *vs64 = NULL;
true_false_string *tfs = NULL;
+ unit_name_string *uns = NULL;
unsigned base;
guint32 mask = wslua_optguint32(L, WSLUA_OPTARG_ProtoField_new_MASK, 0x0);
const gchar *blob = luaL_optstring(L,WSLUA_OPTARG_ProtoField_new_DESCR,NULL);
+ gboolean unit_string = FALSE;
if (!name[0]) {
WSLUA_ARG_ERROR(ProtoField_new,NAME,"cannot be an empty string");
@@ -410,6 +477,10 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) {
case FT_INT24:
case FT_INT32:
case FT_INT64:
+ if (type != FT_CHAR && base & BASE_UNIT_STRING) {
+ unit_string = TRUE;
+ base &= ~BASE_UNIT_STRING;
+ }
if (base == BASE_NONE) {
if (type == FT_CHAR)
base = BASE_OCT; /* default base for characters (BASE_HEX instead?) */
@@ -417,7 +488,7 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) {
base = BASE_DEC; /* Default base for integer */
} else if (base < BASE_DEC || base > BASE_HEX_DEC) {
WSLUA_OPTARG_ERROR(ProtoField_new,BASE,"Base must be either base.DEC, base.HEX, base.OCT,"
- " base.DEC_HEX, base.DEC_HEX or base.HEX_DEC");
+ " base.DEC_HEX, base.DEC_HEX, base.HEX_DEC or base.UNIT_STRING");
return 0;
}
if ((base == BASE_HEX || base == BASE_OCT) &&
@@ -426,8 +497,12 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) {
WSLUA_OPTARG_ERROR(ProtoField_new,BASE,"This type does not display as hexadecimal");
return 0;
}
- if (nargs >= WSLUA_OPTARG_ProtoField_new_VALUESTRING && !lua_isnil(L,WSLUA_OPTARG_ProtoField_new_VALUESTRING)) {
- if (type == FT_UINT64 || type == FT_INT64) {
+ if (nargs >= WSLUA_OPTARG_ProtoField_new_VALUESTRING &&
+ !lua_isnil(L,WSLUA_OPTARG_ProtoField_new_VALUESTRING))
+ {
+ if (unit_string) {
+ uns = unit_name_string_from_table(L,WSLUA_OPTARG_ProtoField_new_VALUESTRING);
+ } else if (type == FT_UINT64 || type == FT_INT64) {
vs64 = val64_string_from_table(L,WSLUA_OPTARG_ProtoField_new_VALUESTRING);
} else {
vs32 = value_string_from_table(L,WSLUA_OPTARG_ProtoField_new_VALUESTRING);
@@ -459,13 +534,21 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) {
return 0;
}
break;
+ case FT_FLOAT:
+ case FT_DOUBLE:
+ if ((base & BASE_UNIT_STRING) &&
+ (nargs >= WSLUA_OPTARG_ProtoField_new_VALUESTRING) &&
+ !lua_isnil(L,WSLUA_OPTARG_ProtoField_new_VALUESTRING))
+ {
+ base &= ~BASE_UNIT_STRING;
+ uns = unit_name_string_from_table(L,WSLUA_OPTARG_ProtoField_new_VALUESTRING);
+ }
+ /* FALLTHRU */
case FT_NONE:
case FT_IPv4:
case FT_IPv6:
case FT_IPXNET:
case FT_ETHER:
- case FT_FLOAT:
- case FT_DOUBLE:
case FT_RELATIVE_TIME:
case FT_STRING:
case FT_STRINGZ:
@@ -525,6 +608,9 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) {
/* Indicate that we are using val64_string */
f->base |= BASE_VAL64_STRING;
f->vs = VALS(vs64);
+ } else if (uns) {
+ f->base |= BASE_UNIT_STRING;
+ f->vs = uns;
} else if (framenum_type) {
f->vs = FRAMENUM_TYPE(framenum_type);
} else {
@@ -551,6 +637,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) {
enum ft_framenum_type framenum_type = FT_FRAMENUM_NONE;
value_string* vs32 = NULL;
val64_string* vs64 = NULL;
+ unit_name_string* uns = NULL;
guint32 mask = wslua_optguint32(L,5,0);
const gchar* blob = luaL_optstring(L,6,NULL);
@@ -566,6 +653,12 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) {
luaL_argerror(L, 4, "Invalid frametype");
return 0;
}
+ } else if (base & BASE_UNIT_STRING) {
+ uns = unit_name_string_from_table(L,4);
+ base &= ~BASE_UNIT_STRING;
+ if (base == BASE_NONE) {
+ base = BASE_DEC;
+ }
} else if (type == FT_UINT64 || type == FT_INT64) {
vs64 = val64_string_from_table(L,4);
} else {
@@ -580,7 +673,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) {
luaL_argerror(L, 5, "FRAMENUM can not have a bitmask");
} else if (base < BASE_DEC || base > BASE_HEX_DEC) {
luaL_argerror(L, 3, "Base must be either base.DEC, base.HEX, base.OCT,"
- " base.DEC_HEX, base.DEC_HEX or base.HEX_DEC");
+ " base.DEC_HEX, base.DEC_HEX, base.HEX_DEC or base.UNIT_STRING");
return 0;
} else if ((base == BASE_HEX || base == BASE_OCT) &&
(type == FT_INT8 || type == FT_INT16 || type == FT_INT24 || type == FT_INT32 || type == FT_INT64)) {
@@ -602,6 +695,9 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) {
f->vs = VALS(vs64);
} else if (vs32) {
f->vs = VALS(vs32);
+ } else if (uns) {
+ f->base |= BASE_UNIT_STRING;
+ f->vs = uns;
} else if (framenum_type) {
f->vs = FRAMENUM_TYPE(framenum_type);
} else {
@@ -623,8 +719,8 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) {
/* _WSLUA_CONSTRUCTOR_ ProtoField_uint8 Creates a `ProtoField` of an unsigned 8-bit integer (i.e., a byte). */
/* WSLUA_ARG_Protofield_uint8_ABBR Abbreviated name of the field (the string used in filters). */
/* WSLUA_OPTARG_Protofield_uint8_NAME Actual name of the field (the string that appears in the tree). */
-/* WSLUA_OPTARG_Protofield_uint8_BASE One of `base.DEC`, `base.HEX` or `base.OCT`. */
-/* WSLUA_OPTARG_Protofield_uint8_VALUESTRING A table containing the text that corresponds to the values. */
+/* WSLUA_OPTARG_Protofield_uint8_BASE One of `base.DEC`, `base.HEX` or `base.OCT`, `base.DEC_HEX`, `base.HEX_DEC` or `base.UNIT_STRING`. */
+/* WSLUA_OPTARG_Protofield_uint8_VALUESTRING A table containing the text that corresponds to the values, or a table containing unit name for the values if base is `base.UNIT_STRING`. */
/* WSLUA_OPTARG_Protofield_uint8_MASK Integer mask of this field. */
/* WSLUA_OPTARG_Protofield_uint8_DESC Description of the field. */
/* _WSLUA_RETURNS_ A `ProtoField` object to be added to a table set to the `Proto.fields` attribute. */
@@ -632,8 +728,8 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) {
/* _WSLUA_CONSTRUCTOR_ ProtoField_uint16 Creates a `ProtoField` of an unsigned 16-bit integer. */
/* WSLUA_ARG_Protofield_uint16_ABBR Abbreviated name of the field (the string used in filters). */
/* WSLUA_OPTARG_Protofield_uint16_NAME Actual name of the field (the string that appears in the tree). */
-/* WSLUA_OPTARG_Protofield_uint16_BASE One of `base.DEC`, `base.HEX` or `base.OCT`. */
-/* WSLUA_OPTARG_Protofield_uint16_VALUESTRING A table containing the text that corresponds to the values. */
+/* WSLUA_OPTARG_Protofield_uint16_BASE One of `base.DEC`, `base.HEX`, `base.OCT`, `base.DEC_HEX`, `base.HEX_DEC` or `base.UNIT_STRING`. */
+/* WSLUA_OPTARG_Protofield_uint16_VALUESTRING A table containing the text that corresponds to the values, or a table containing unit name for the values if base is `base.UNIT_STRING`. */
/* WSLUA_OPTARG_Protofield_uint16_MASK Integer mask of this field. */
/* WSLUA_OPTARG_Protofield_uint16_DESC Description of the field. */
/* _WSLUA_RETURNS_ A `ProtoField` object to be added to a table set to the `Proto.fields` attribute. */
@@ -641,8 +737,8 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) {
/* _WSLUA_CONSTRUCTOR_ ProtoField_uint24 Creates a `ProtoField` of an unsigned 24-bit integer. */
/* WSLUA_ARG_Protofield_uint24_ABBR Abbreviated name of the field (the string used in filters). */
/* WSLUA_OPTARG_Protofield_uint24_NAME Actual name of the field (the string that appears in the tree). */
-/* WSLUA_OPTARG_Protofield_uint24_BASE One of `base.DEC`, `base.HEX` or `base.OCT`. */
-/* WSLUA_OPTARG_Protofield_uint24_VALUESTRING A table containing the text that corresponds to the values. */
+/* WSLUA_OPTARG_Protofield_uint24_BASE One of `base.DEC`, `base.HEX`, `base.OCT`, `base.DEC_HEX`, `base.HEX_DEC` or `base.UNIT_STRING`. */
+/* WSLUA_OPTARG_Protofield_uint24_VALUESTRING A table containing the text that corresponds to the values, or a table containing unit name for the values if base is `base.UNIT_STRING`. */
/* WSLUA_OPTARG_Protofield_uint24_MASK Integer mask of this field. */
/* WSLUA_OPTARG_Protofield_uint24_DESC Description of the field. */
/* _WSLUA_RETURNS_ A `ProtoField` object to be added to a table set to the `Proto.fields` attribute. */
@@ -650,8 +746,8 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) {
/* _WSLUA_CONSTRUCTOR_ ProtoField_uint32 Creates a `ProtoField` of an unsigned 32-bit integer. */
/* WSLUA_ARG_Protofield_uint32_ABBR Abbreviated name of the field (the string used in filters). */
/* WSLUA_OPTARG_Protofield_uint32_NAME Actual name of the field (the string that appears in the tree). */
-/* WSLUA_OPTARG_Protofield_uint32_BASE One of `base.DEC`, `base.HEX` or `base.OCT`. */
-/* WSLUA_OPTARG_Protofield_uint32_VALUESTRING A table containing the text that corresponds to the values. */
+/* WSLUA_OPTARG_Protofield_uint32_BASE One of `base.DEC`, `base.HEX`, `base.OCT`, `base.DEC_HEX`, `base.HEX_DEC` or `base.UNIT_STRING`. */
+/* WSLUA_OPTARG_Protofield_uint32_VALUESTRING A table containing the text that corresponds to the values, or a table containing unit name for the values if base is `base.UNIT_STRING`. */
/* WSLUA_OPTARG_Protofield_uint32_MASK Integer mask of this field. */
/* WSLUA_OPTARG_Protofield_uint32_DESC Description of the field. */
/* _WSLUA_RETURNS_ A `ProtoField` object to be added to a table set to the `Proto.fields` attribute. */
@@ -659,8 +755,8 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) {
/* _WSLUA_CONSTRUCTOR_ ProtoField_uint64 Creates a `ProtoField` of an unsigned 64-bit integer. */
/* WSLUA_ARG_Protofield_uint64_ABBR Abbreviated name of the field (the string used in filters). */
/* WSLUA_OPTARG_Protofield_uint64_NAME Actual name of the field (the string that appears in the tree). */
-/* WSLUA_OPTARG_Protofield_uint64_BASE One of `base.DEC`, `base.HEX` or `base.OCT`. */
-/* WSLUA_OPTARG_Protofield_uint64_VALUESTRING A table containing the text that corresponds to the values. */
+/* WSLUA_OPTARG_Protofield_uint64_BASE One of `base.DEC`, `base.HEX`, `base.OCT`, `base.DEC_HEX`, `base.HEX_DEC` or `base.UNIT_STRING`. */
+/* WSLUA_OPTARG_Protofield_uint64_VALUESTRING A table containing the text that corresponds to the values, or a table containing unit name for the values if base is `base.UNIT_STRING`. */
/* WSLUA_OPTARG_Protofield_uint64_MASK Integer mask of this field. */
/* WSLUA_OPTARG_Protofield_uint64_DESC Description of the field. */
/* _WSLUA_RETURNS_ A `ProtoField` object to be added to a table set to the `Proto.fields` attribute. */
@@ -668,8 +764,8 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) {
/* _WSLUA_CONSTRUCTOR_ ProtoField_int8 Creates a `ProtoField` of a signed 8-bit integer (i.e., a byte). */
/* WSLUA_ARG_Protofield_int8_ABBR Abbreviated name of the field (the string used in filters). */
/* WSLUA_OPTARG_Protofield_int8_NAME Actual name of the field (the string that appears in the tree). */
-/* WSLUA_OPTARG_Protofield_int8_BASE One of `base.DEC`, `base.HEX` or `base.OCT`. */
-/* WSLUA_OPTARG_Protofield_int8_VALUESTRING A table containing the text that corresponds to the values. */
+/* WSLUA_OPTARG_Protofield_int8_BASE One of `base.DEC`, `base.HEX`, `base.OCT` or `base.UNIT_STRING`. */
+/* WSLUA_OPTARG_Protofield_int8_VALUESTRING A table containing the text that corresponds to the values, or a table containing unit name for the values if base is `base.UNIT_STRING`. */
/* WSLUA_OPTARG_Protofield_int8_MASK Integer mask of this field. */
/* WSLUA_OPTARG_Protofield_int8_DESC Description of the field. */
/* _WSLUA_RETURNS_ A `ProtoField` object to be added to a table set to the `Proto.fields` attribute. */
@@ -677,8 +773,8 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) {
/* _WSLUA_CONSTRUCTOR_ ProtoField_int16 Creates a `ProtoField` of a signed 16-bit integer. */
/* WSLUA_ARG_Protofield_int16_ABBR Abbreviated name of the field (the string used in filters). */
/* WSLUA_OPTARG_Protofield_int16_NAME Actual name of the field (the string that appears in the tree). */
-/* WSLUA_OPTARG_Protofield_int16_BASE One of `base.DEC`, `base.HEX` or `base.OCT`. */
-/* WSLUA_OPTARG_Protofield_int16_VALUESTRING A table containing the text that corresponds to the values. */
+/* WSLUA_OPTARG_Protofield_int16_BASE One of `base.DEC`, `base.HEX`, `base.OCT` or `base.UNIT_STRING`. */
+/* WSLUA_OPTARG_Protofield_int16_VALUESTRING A table containing the text that corresponds to the values, or a table containing unit name for the values if base is `base.UNIT_STRING`. */
/* WSLUA_OPTARG_Protofield_int16_MASK Integer mask of this field. */
/* WSLUA_OPTARG_Protofield_int16_DESC Description of the field. */
/* _WSLUA_RETURNS_ A `ProtoField` object to be added to a table set to the `Proto.fields` attribute. */
@@ -686,8 +782,8 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) {
/* _WSLUA_CONSTRUCTOR_ ProtoField_int24 Creates a `ProtoField` of a signed 24-bit integer. */
/* WSLUA_ARG_Protofield_int24_ABBR Abbreviated name of the field (the string used in filters). */
/* WSLUA_OPTARG_Protofield_int24_NAME Actual name of the field (the string that appears in the tree). */
-/* WSLUA_OPTARG_Protofield_int24_BASE One of `base.DEC`, `base.HEX` or `base.OCT`. */
-/* WSLUA_OPTARG_Protofield_int24_VALUESTRING A table containing the text that corresponds to the values. */
+/* WSLUA_OPTARG_Protofield_int24_BASE One of `base.DEC`, `base.HEX`, `base.OCT` or `base.UNIT_STRING`. */
+/* WSLUA_OPTARG_Protofield_int24_VALUESTRING A table containing the text that corresponds to the values, or a table containing unit name for the values if base is `base.UNIT_STRING`. */
/* WSLUA_OPTARG_Protofield_int24_MASK Integer mask of this field. */
/* WSLUA_OPTARG_Protofield_int24_DESC Description of the field. */
/* _WSLUA_RETURNS_ A `ProtoField` object to be added to a table set to the `Proto.fields` attribute. */
@@ -695,8 +791,8 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) {
/* _WSLUA_CONSTRUCTOR_ ProtoField_int32 Creates a `ProtoField` of a signed 32-bit integer. */
/* WSLUA_ARG_Protofield_int32_ABBR Abbreviated name of the field (the string used in filters). */
/* WSLUA_OPTARG_Protofield_int32_NAME Actual name of the field (the string that appears in the tree). */
-/* WSLUA_OPTARG_Protofield_int32_BASE One of `base.DEC`, `base.HEX` or `base.OCT`. */
-/* WSLUA_OPTARG_Protofield_int32_VALUESTRING A table containing the text that corresponds to the values. */
+/* WSLUA_OPTARG_Protofield_int32_BASE One of `base.DEC`, `base.HEX`, `base.OCT` or `base.UNIT_STRING`. */
+/* WSLUA_OPTARG_Protofield_int32_VALUESTRING A table containing the text that corresponds to the values, or a table containing unit name for the values if base is `base.UNIT_STRING`. */
/* WSLUA_OPTARG_Protofield_int32_MASK Integer mask of this field. */
/* WSLUA_OPTARG_Protofield_int32_DESC Description of the field. */
/* _WSLUA_RETURNS_ A `ProtoField` object to be added to a table set to the `Proto.fields` attribute. */
@@ -704,8 +800,8 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) {
/* _WSLUA_CONSTRUCTOR_ ProtoField_int64 Creates a `ProtoField` of a signed 64-bit integer. */
/* WSLUA_ARG_Protofield_int64_ABBR Abbreviated name of the field (the string used in filters). */
/* WSLUA_OPTARG_Protofield_int64_NAME Actual name of the field (the string that appears in the tree). */
-/* WSLUA_OPTARG_Protofield_int64_BASE One of `base.DEC`, `base.HEX` or `base.OCT`. */
-/* WSLUA_OPTARG_Protofield_int64_VALUESTRING A table containing the text that corresponds to the values. */
+/* WSLUA_OPTARG_Protofield_int64_BASE One of `base.DEC`, `base.HEX`, `base.OCT` or `base.UNIT_STRING`. */
+/* WSLUA_OPTARG_Protofield_int64_VALUESTRING A table containing the text that corresponds to the values, or a table containing unit name for the values if base is `base.UNIT_STRING`. */
/* WSLUA_OPTARG_Protofield_int64_MASK Integer mask of this field. */
/* WSLUA_OPTARG_Protofield_int64_DESC Description of the field. */
/* _WSLUA_RETURNS_ A `ProtoField` object to be added to a table set to the `Proto.fields` attribute. */
@@ -852,6 +948,69 @@ static int ProtoField_time(lua_State* L,enum ftenum type) {
PROTOFIELD_TIME(absolute_time,FT_ABSOLUTE_TIME)
+static int ProtoField_floating(lua_State* L,enum ftenum type) {
+ ProtoField f;
+ const gchar* abbr = check_field_name(L,1,type);
+ const gchar* name = luaL_optstring(L,2,abbr);
+ unit_name_string* uns = NULL;
+ const gchar* blob;
+
+ if (!name[0]) {
+ luaL_argerror(L, 2, "cannot be an empty string");
+ return 0;
+ }
+
+ if (lua_istable(L, 3)) {
+ uns = unit_name_string_from_table(L,3);
+ blob = luaL_optstring(L,4,NULL);
+ } else {
+ blob = luaL_optstring(L,3,NULL);
+ }
+
+ f = g_new(wslua_field_t,1);
+
+ f->hfid = -2;
+ f->ett = -1;
+ f->name = g_strdup(name);
+ f->abbrev = g_strdup(abbr);
+ f->type = type;
+ if (uns) {
+ f->vs = uns;
+ f->base = BASE_NONE | BASE_UNIT_STRING;
+ } else {
+ f->vs = NULL;
+ f->base = BASE_NONE;
+ }
+ f->mask = 0;
+ if (blob && strcmp(blob, f->name) != 0) {
+ f->blob = g_strdup(blob);
+ } else {
+ f->blob = NULL;
+ }
+
+ pushProtoField(L,f);
+
+ return 1;
+}
+
+#define PROTOFIELD_FLOATING(lower,FT) static int ProtoField_##lower(lua_State* L) { return ProtoField_floating(L,FT); }
+/* _WSLUA_CONSTRUCTOR_ ProtoField_float Creates a `ProtoField` of a floating point number (4 bytes). */
+/* WSLUA_ARG_Protofield_float_ABBR Abbreviated name of the field (the string used in filters). */
+/* WSLUA_OPTARG_Protofield_float_NAME Actual name of the field (the string that appears in the tree). */
+/* WSLUA_OPTARG_Protofield_float_VALUESTRING A table containing unit name for the values. */
+/* WSLUA_OPTARG_Protofield_float_DESC Description of the field. */
+/* _WSLUA_RETURNS_ A `ProtoField` object to be added to a table set to the `Proto.fields` attribute. */
+
+/* _WSLUA_CONSTRUCTOR_ ProtoField_double Creates a `ProtoField` of a double-precision floating point (8 bytes). */
+/* WSLUA_ARG_Protofield_double_ABBR Abbreviated name of the field (the string used in filters). */
+/* WSLUA_OPTARG_Protofield_double_NAME Actual name of the field (the string that appears in the tree). */
+/* WSLUA_OPTARG_Protofield_double_VALUESTRING A table containing unit name for the values. */
+/* WSLUA_OPTARG_Protofield_double_DESC Description of the field. */
+/* _WSLUA_RETURNS_ A `ProtoField` object to be added to a table set to the `Proto.fields` attribute. */
+
+PROTOFIELD_FLOATING(float,FT_FLOAT)
+PROTOFIELD_FLOATING(double,FT_DOUBLE)
+
static int ProtoField_other(lua_State* L,enum ftenum type) {
ProtoField f;
const gchar* abbr = check_field_name(L,1,type);
@@ -909,18 +1068,6 @@ static int ProtoField_other(lua_State* L,enum ftenum type) {
/* WSLUA_OPTARG_Protofield_ether_DESC Description of the field. */
/* _WSLUA_RETURNS_ A `ProtoField` object to be added to a table set to the `Proto.fields` attribute. */
-/* _WSLUA_CONSTRUCTOR_ ProtoField_float Creates a `ProtoField` of a floating point number (4 bytes). */
-/* WSLUA_ARG_Protofield_float_ABBR Abbreviated name of the field (the string used in filters). */
-/* WSLUA_OPTARG_Protofield_float_NAME Actual name of the field (the string that appears in the tree). */
-/* WSLUA_OPTARG_Protofield_float_DESC Description of the field. */
-/* _WSLUA_RETURNS_ A `ProtoField` object to be added to a table set to the `Proto.fields` attribute. */
-
-/* _WSLUA_CONSTRUCTOR_ ProtoField_double Creates a `ProtoField` of a double-precision floating point (8 bytes). */
-/* WSLUA_ARG_Protofield_double_ABBR Abbreviated name of the field (the string used in filters). */
-/* WSLUA_OPTARG_Protofield_double_NAME Actual name of the field (the string that appears in the tree). */
-/* WSLUA_OPTARG_Protofield_double_DESC Description of the field. */
-/* _WSLUA_RETURNS_ A `ProtoField` object to be added to a table set to the `Proto.fields` attribute. */
-
/* _WSLUA_CONSTRUCTOR_ ProtoField_string Creates a `ProtoField` of a string value. */
/* WSLUA_ARG_Protofield_string_ABBR Abbreviated name of the field (the string used in filters). */
/* WSLUA_OPTARG_Protofield_string_NAME Actual name of the field (the string that appears in the tree). */
@@ -986,8 +1133,6 @@ PROTOFIELD_OTHER(ipv4,FT_IPv4)
PROTOFIELD_OTHER(ipv6,FT_IPv6)
PROTOFIELD_OTHER(ipx,FT_IPXNET)
PROTOFIELD_OTHER(ether,FT_ETHER)
-PROTOFIELD_OTHER(float,FT_FLOAT)
-PROTOFIELD_OTHER(double,FT_DOUBLE)
PROTOFIELD_OTHER(relative_time,FT_RELATIVE_TIME)
PROTOFIELD_OTHER(string,FT_STRING)
PROTOFIELD_OTHER(stringz,FT_STRINGZ)