l0.DependencyControl.Enum¶
Enum ¶
An immutable enumeration type with value/key reverse lookup.
Constructor ¶
Creates an enum from a table of key/value pairs or a list of names.
| param | type | description |
|---|---|---|
| name | string |
|
| values | table |
Key/value pairs, or a list of names whose value defaults to their position. |
| logger? | Logger | Logger for enum error messages (default: a shared logger). |
Instance methods¶
test ¶
Returns whether the given key is defined in this enum.
| param | type | description |
|---|---|---|
| key | string |
Returns:
definedbooleanvalueany— The value mapped to the key, or nil if undefined.
describe ¶
Returns a human-readable description of the given value(s) in this enum.
| param | type | description |
|---|---|---|
| values? | any |
A single value, or a list of values to look up. If not provided, returns all keys. |
| pattern? | fun(key: string, value: any): string |
A function to format the key/value pair for display (default " |
| join? | string|boolean |
Separator string for joining multiple keys, true for ", ", or false to return a list (default true). |
Returns:
resultstring|string[] — A single string when joining, or a list of the formatted keys when join is false.
validate ¶
Validates that a value is a member of this enum.
| param | type | description |
|---|---|---|
| value | any |
|
| argName? | string |
Argument name to include in the error message. |
Returns:
validboolean? — True when the value is a member, nil otherwise.errstring? — Validation error message when invalid.
Class methods¶
isReservedKey ¶
Reports whether k is reserved as an enum key — a built-in member name or __-prefixed.
| param | type | description |
|---|---|---|
| k | string |
Returns:
reservedboolean