Skip to main content

Interface: EnumDef

A name -> value mapping over an integer field, from defineEnum.

Usable as a defineStruct field type (or as the element type of a [ elementType ] field), where it packs from a member name and unpacks back to one. It is not a SimpleType, so it cannot be a dlopen argument or return type on its own — pass EnumDef.type for that.

Properties

members

readonly members: Readonly<Record<string, number>>

The mapping the enum was defined with, frozen.


name

readonly name: string

A description of the mapping, e.g. 'enum(RED, GREEN, BLUE)'.


size

readonly size: number

Size in bytes of EnumDef.type.


type

readonly type: SimpleType<number>

The integer type the enum is stored in, i.e. what libffi lays out. Defaults to types.sint, which is what a C compiler gives an enum whose enumerators fit in an int.

Methods

nameFor()

nameFor(value): string | undefined

The member name for a value, undefined if the enum has none.

Parameters

value

number | bigint

Returns

string | undefined


valueFor()

valueFor(nameOrValue): number | undefined

The integer for a member name, or for a value that is already one of the enum's; undefined for anything else.

Parameters

nameOrValue

string | number | bigint

Returns

number | undefined