dreamworkAPI
Ctrl K
GitHub
libraryDocs / ascii

ascii

librarysharedmenusource

An ASCII library that provides functions for this encoding.

All functions operate on single bytes (integers in the range 0x00–0xFF), as returned by string.byte, and do not accept nil.

Functions

ascii.fromIntegerReturns the digit byte of the given numerical value (0–35), the inverse of ascii.toInteger.
ascii.isAlnumChecks if the byte is an ASCII alphanumeric character (A–Z, a–z, or 0–9).
ascii.isAlphaChecks if the byte is an ASCII alphabetic character (a–z or A–Z).
ascii.isASCIIChecks if the byte is an ASCII character, i.e. in the range 0x00–0x7F.
ascii.isBinaryDigitChecks if the byte is an ASCII binary digit (0–1).
ascii.isBlankChecks if the byte is an ASCII blank character, i.e. space (0x20) or horizontal tab (0x09).
ascii.isControlChecks if the byte is an ASCII control character.
ascii.isDigitChecks if the byte is an ASCII decimal digit (0–9).
ascii.isExtendedChecks if the byte is an extended (non-ASCII) byte, i.e. above 0x7F.
ascii.isGraphicChecks if the byte is a visible ASCII character (0x21–0x7E), i.e. printable and not a space.
ascii.isHexDigitChecks if the byte is a valid hexadecimal digit (0–9, A–F, a–f).
ascii.isLowerChecks if the byte is a lowercase ASCII letter (a–z).
ascii.isMagicChecks if the byte is a Lua pattern magic character.
ascii.isOctalDigitChecks if the byte is an ASCII octal digit (0–7).
ascii.isPrintableChecks if the byte is a printable ASCII character (0x20–0x7E), space included.
ascii.isSpaceChecks if the byte is an ASCII whitespace character.
ascii.isSpecialChecks if the byte is an ASCII special (punctuation/symbol) character.
ascii.isUpperChecks if the byte is an uppercase ASCII letter (A–Z).
ascii.isWordChecks if the byte is an ASCII word character (A–Z, a–z, 0–9 or _), i.e. a character allowed in identifiers.
ascii.toIntegerReturns the numerical value of the given digit byte (0–9, then a–z/A–Z for 10–35).
ascii.toLowerConverts an uppercase ASCII letter to lowercase, any other byte is returned as is.
ascii.toUpperConverts a lowercase ASCII letter to uppercase, any other byte is returned as is.

#ascii.fromInteger

sharedmenunodiscardsource
function ascii.fromInteger(value: ascii.integer, uppercase?: boolean): byte | nil

Returns the digit byte of the given numerical value (0–35), the inverse of ascii.toInteger.

Parameters
NameTypeDescription
valueascii.integerThe digit value to convert.
uppercaseoptionalbooleanIf true, letters are returned in uppercase. Defaults to false.
Returns
TypeNameDescription
byte | niluint8The digit byte, or nil if the value is out of range.
See also

#ascii.isAlnum

sharedmenunodiscardsource
function ascii.isAlnum(uint8: byte): boolean

Checks if the byte is an ASCII alphanumeric character (A–Z, a–z, or 0–9).

Parameters
NameTypeDescription
uint8byteThe byte to check.
Returns
TypeNameDescription
booleanis_alnumtrue if the byte is an ASCII letter or decimal digit.

#ascii.isAlpha

sharedmenunodiscardsource
function ascii.isAlpha(uint8: byte): boolean

Checks if the byte is an ASCII alphabetic character (a–z or A–Z).

Parameters
NameTypeDescription
uint8byteThe byte to check.
Returns
TypeNameDescription
booleanis_alphatrue if the byte is a lowercase or uppercase letter.

#ascii.isASCII

sharedmenunodiscardsource
function ascii.isASCII(uint8: byte): boolean

Checks if the byte is an ASCII character, i.e. in the range 0x00–0x7F.

Parameters
NameTypeDescription
uint8byteThe byte to check.
Returns
TypeNameDescription
booleanis_asciitrue if the byte is not greater than 0x7F.

#ascii.isBinaryDigit

sharedmenunodiscardsource
function ascii.isBinaryDigit(uint8: byte): boolean

Checks if the byte is an ASCII binary digit (0–1).

Parameters
NameTypeDescription
uint8byteThe byte to check.
Returns
TypeNameDescription
booleanis_binary_digittrue if the byte is 0 or 1.

#ascii.isBlank

sharedmenunodiscardsource
function ascii.isBlank(uint8: byte): boolean

Checks if the byte is an ASCII blank character, i.e. space (0x20) or horizontal tab (0x09).

Parameters
NameTypeDescription
uint8byteThe byte to check.
Returns
TypeNameDescription
booleanis_blanktrue if the byte is a space or a horizontal tab.

#ascii.isControl

sharedmenunodiscardsource
function ascii.isControl(uint8: byte): boolean

Checks if the byte is an ASCII control character. Control characters are non-printable bytes in the range 0x00–0x1F (e.g. NUL, BEL, BS, HT, LF, CR) as well as DEL (0x7F).

Parameters
NameTypeDescription
uint8byteThe byte to check.
Returns
TypeNameDescription
booleanis_controltrue if the byte is a control character.

#ascii.isDigit

sharedmenunodiscardsource
function ascii.isDigit(uint8: byte): boolean

Checks if the byte is an ASCII decimal digit (0–9).

Parameters
NameTypeDescription
uint8byteThe byte to check.
Returns
TypeNameDescription
booleanis_digittrue if the byte is in the range 0x30–0x39.

#ascii.isExtended

sharedmenunodiscardsource
function ascii.isExtended(uint8: byte): boolean

Checks if the byte is an extended (non-ASCII) byte, i.e. above 0x7F. These bytes appear in multi-byte UTF-8 sequences and Latin-1 supplements.

Parameters
NameTypeDescription
uint8byteThe byte to check.
Returns
TypeNameDescription
booleanis_extendedtrue if the byte is greater than 0x7F.

#ascii.isGraphic

sharedmenunodiscardsource
function ascii.isGraphic(uint8: byte): boolean

Checks if the byte is a visible ASCII character (0x21–0x7E), i.e. printable and not a space.

Parameters
NameTypeDescription
uint8byteThe byte to check.
Returns
TypeNameDescription
booleanis_graphictrue if the byte has a visible glyph.

#ascii.isHexDigit

sharedmenunodiscardsource
function ascii.isHexDigit(uint8: byte): boolean

Checks if the byte is a valid hexadecimal digit (0–9, A–F, a–f).

Parameters
NameTypeDescription
uint8byteThe byte to check.
Returns
TypeNameDescription
booleanis_hex_digittrue if the byte is a decimal digit or a hex letter.

#ascii.isLower

sharedmenunodiscardsource
function ascii.isLower(uint8: byte): boolean

Checks if the byte is a lowercase ASCII letter (a–z).

Parameters
NameTypeDescription
uint8byteThe byte to check.
Returns
TypeNameDescription
booleanis_lowertrue if the byte is in the range 0x61–0x7A.

#ascii.isMagic

sharedmenunodiscardsource
function ascii.isMagic(uint8: byte): boolean

Checks if the byte is a Lua pattern magic character. Magic characters have special meaning inside Lua string patterns and must be escaped with % when used as literals. The magic set is: ^ $ ( ) % . [ ] * + - ?

Parameters
NameTypeDescription
uint8byteThe byte to check.
Returns
TypeNameDescription
booleanis_magictrue if the byte is a Lua pattern magic character.

#ascii.isOctalDigit

sharedmenunodiscardsource
function ascii.isOctalDigit(uint8: byte): boolean

Checks if the byte is an ASCII octal digit (0–7).

Parameters
NameTypeDescription
uint8byteThe byte to check.
Returns
TypeNameDescription
booleanis_octal_digittrue if the byte is in the range 0x30–0x37.

#ascii.isPrintable

sharedmenunodiscardsource
function ascii.isPrintable(uint8: byte): boolean

Checks if the byte is a printable ASCII character (0x20–0x7E), space included.

Parameters
NameTypeDescription
uint8byteThe byte to check.
Returns
TypeNameDescription
booleanis_printabletrue if the byte is a printable character.

#ascii.isSpace

sharedmenunodiscardsource
function ascii.isSpace(uint8: byte): boolean

Checks if the byte is an ASCII whitespace character. Matches: space (0x20), horizontal tab (0x09), line feed (0x0A), vertical tab (0x0B), form feed (0x0C), and carriage return (0x0D).

Parameters
NameTypeDescription
uint8byteThe byte to check.
Returns
TypeNameDescription
booleanis_spacetrue if the byte is a whitespace character, false otherwise.

#ascii.isSpecial

sharedmenunodiscardsource
function ascii.isSpecial(uint8: byte): boolean

Checks if the byte is an ASCII special (punctuation/symbol) character. Covers the following ranges: ! – / (0x21–0x2F), : – @ (0x3A–0x40), `[ – ` (0x5B–0x60), { – ~` (0x7B–0x7E).

Parameters
NameTypeDescription
uint8byteThe byte to check.
Returns
TypeNameDescription
booleanis_specialtrue if the byte is a punctuation or symbol character.

#ascii.isUpper

sharedmenunodiscardsource
function ascii.isUpper(uint8: byte): boolean

Checks if the byte is an uppercase ASCII letter (A–Z).

Parameters
NameTypeDescription
uint8byteThe byte to check.
Returns
TypeNameDescription
booleanis_uppertrue if the byte is in the range 0x41–0x5A.

#ascii.isWord

sharedmenunodiscardsource
function ascii.isWord(uint8: byte): boolean

Checks if the byte is an ASCII word character (A–Z, a–z, 0–9 or _), i.e. a character allowed in identifiers.

Parameters
NameTypeDescription
uint8byteThe byte to check.
Returns
TypeNameDescription
booleanis_wordtrue if the byte is an ASCII letter, decimal digit or underscore.

#ascii.toInteger

sharedmenunodiscardsource
function ascii.toInteger(uint8: byte): ascii.integer | nil

Returns the numerical value of the given digit byte (0–9, then a–z/A–Z for 10–35).

Parameters
NameTypeDescription
uint8byteThe byte to convert.
Returns
TypeNameDescription
ascii.integer | nilnumberThe digit value, or nil if the byte is not a valid digit.
See also

#ascii.toLower

sharedmenunodiscardsource
function ascii.toLower(uint8: byte): byte

Converts an uppercase ASCII letter to lowercase, any other byte is returned as is.

Parameters
NameTypeDescription
uint8byteThe byte to convert.
Returns
TypeNameDescription
bytelower_uint8The lowercase byte.

#ascii.toUpper

sharedmenunodiscardsource
function ascii.toUpper(uint8: byte): byte

Converts a lowercase ASCII letter to uppercase, any other byte is returned as is.

Parameters
NameTypeDescription
uint8byteThe byte to convert.
Returns
TypeNameDescription
byteupper_uint8The uppercase byte.
Generated from the dreamwork meta branch.