mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00

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.
22 lines
451 B
Text
22 lines
451 B
Text
# @TEST-EXEC: zeek -b %INPUT >out
|
|
# @TEST-EXEC: btest-diff out
|
|
|
|
type Color: enum { RED, GREEN, BLUE };
|
|
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");
|