Lulu Enums — Count and Iteration
Introduction
The Enum
class has two methods that allow you to count and iterate over the enumerators.
Enum:count
The Enum:count()
method returns the number of enumerators in the Enum
.
Example
'Suit' { 'Clubs', 'Diamonds', 'Hearts', 'Spades' }
ENUM ("There are %d enumerators in the enum %q.", Suit:count(), Suit:type()) putln
This outputs:
There are 4 enumerators in the enum "Suit".
Enum:iter
The Enum:iter()
method returns an iterator that traverses the enumerators of the Enum
in sorted order.
Example
'Suit' { 'Clubs', 'Diamonds', 'Hearts', 'Spades' }
ENUM for e in Suit:iter() do
("Enumerator: %s has ordinal value %d", e, e:tonumber())
putlnend
This outputs:
Enumerator: Clubs has ordinal value 1
Enumerator: Diamonds has ordinal value 2
Enumerator: Hearts has ordinal value 3 Enumerator: Spades has ordinal value 4