mirror of
https://github.com/zeek/zeek.git
synced 2025-10-05 16:18:19 +00:00
enum_names: Support naming types with a string
In his ZeekWeek 2022 presentation, @stevesmoot mentioned that he had a difficult time looking up enum names when all he had was a string naming the type. Add support to enum_names() to transparently lookup the type if a string is provided. This is similar in how record_fields() behaves when being passed a string.
This commit is contained in:
parent
7f7c77ab07
commit
a00cef9920
4 changed files with 47 additions and 6 deletions
|
@ -1,4 +1,20 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
with types
|
||||
{
|
||||
Monochrome::WHITE,
|
||||
Monochrome::BLACK
|
||||
}
|
||||
{
|
||||
RED,
|
||||
GREEN,
|
||||
PURPLE,
|
||||
BLUE
|
||||
}
|
||||
{
|
||||
Monochrome::WHITE,
|
||||
Monochrome::BLACK
|
||||
}
|
||||
with strings
|
||||
{
|
||||
RED,
|
||||
GREEN,
|
||||
|
@ -11,3 +27,7 @@ GREEN,
|
|||
PURPLE,
|
||||
BLUE
|
||||
}
|
||||
{
|
||||
Monochrome::WHITE,
|
||||
Monochrome::BLACK
|
||||
}
|
||||
|
|
|
@ -6,5 +6,17 @@ type ColorAlias: Color;
|
|||
|
||||
redef enum Color += { PURPLE };
|
||||
|
||||
module Monochrome;
|
||||
|
||||
type Color: enum { WHITE, BLACK };
|
||||
|
||||
|
||||
print "with types";
|
||||
print enum_names(Color);
|
||||
print enum_names(ColorAlias);
|
||||
print enum_names(Monochrome::Color);
|
||||
|
||||
print "with strings";
|
||||
print enum_names("Color");
|
||||
print enum_names("ColorAlias");
|
||||
print enum_names("Monochrome::Color");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue