Next: , Previous: , Up: Naming Conventions   [Contents][Index]


1.2.2 Enums and Constants

SDL enumerated types and constants are passed and returned as symbols, thus enforcing their "constant" nature and for ease of use in case statements. Flags, such as the SDL initialization flags and video surface flags, are treated as lists of symbols, each constant in the flag group that you would or together in C code becoming a symbol in the list.

Some of these symbols retain their exact C names, while others are adapted to better fit Scheme (mostly by removing the ‘SDL_’ prefix, changing underscores to hyphens, downcasing, and inserting a hyphen between “words”).

A particular set of enums is called an enumstash. Likewise flagstash for flags.

You can use kotk to examine the enums and flags encapsulated by these respectively typed objects. You can also use integers where enums/flags are expected, and can convert between the symbol and numeric value with enum->number, number->enum, flags->number and number->flags.

The conversion procs all take stash as the first argument, a symbol that identifies the particular set of enums/flags. For backward compatibility, stash may also be such an object, but this support will be removed after 2013-12-31, when those objects are to be fully internalized.

Procedure: kotk [name]

Return the contents of stash name (a symbol), as an alist with symbolic keys, integer values. If name is omitted, the keys are the names of the all the enum- and flagstashes, and the values have the form:

(N TYPE)

where n is the count of symbols in that stash, and type is a symbol: enums or flags.

Procedure: enum->number stash symbol

Return the number in stash associated with symbol.

Procedure: number->enum stash number

Return the symbol associated with number, or #f if it does not belong to stash.

Procedure: flags->number stash flags

Use stash to convert flags to a number. flags is a list of symbols; or #f, which is taken as the empty list; or #t, which is taken as the list of all possible symbols in stash.

Procedure: number->flags stash number

Use stash to convert number to a list of symbols. If the flags in stash are not sufficient to decode number, the first element of the list is the numeric remainder.

Conversion from symbols to numbers (including enum->number and flags->number) throws an error with key non-member-symbol if the specified symbol is not a member of the respective enumstash or flagstash.


Next: Create and Make, Previous: Renaming C Functions, Up: Naming Conventions   [Contents][Index]