[ADD] builtin function enum_to_int()

[ADD] added tests for the new enum_to_int function
This commit is contained in:
Christian Struck 2014-11-10 17:58:38 -08:00
parent 9045288ad3
commit b36d5fc81b
3 changed files with 50 additions and 0 deletions

View file

@ -2159,6 +2159,21 @@ function counts_to_addr%(v: index_vec%): addr
}
%}
## Converts an :bro:type:`enum` to an :bro:type:`int`
##
## e: The :bro:type:`enum` to convert.
##
## Returns: The :bro:type:`enum` as :bro:type:`int`.
function enum_to_int%(e: any%): int
%{
if ( e->Type()->Tag() != TYPE_ENUM )
{
builtin_error("enum_to_int() requires enum_val");
return new Val(-1, TYPE_INT);
}
return new Val(e->AsEnum(), TYPE_INT);
%}
## Converts a :bro:type:`string` to an :bro:type:`int`.
##
## str: The :bro:type:`string` to convert.