Next: Frobs

Prev: Dictionaries

Buffers

A buffer is a vector of unsigned eight-bit values, intended primarily for network I/O. Although they are not as convenient to use as strings, they can contain any character value, while strings can contain only printable characters.

You can construct a buffer using a buffer construction expression, which has the following syntax:

%[byte1, byte2, ...]
The result of a buffer construction expression is a buffer containing the byte values expressed by byte1, byte2, ..., all of which must be integers. If any of the values of byte1, byte2, ... cannot fit inside an unsigned eight-bit number, then that byte will contain the lower order eight bits of the specified number.

Apart from operations which apply to all data types, the only language operations which apply to buffers are the functions whose names begin with buffer_: buffer_len(), buffer_retrieve(), buffer_append(), buffer_replace(), buffer_add(), buffer_truncate(), buffer_to_strings(), and buffer_from_strings(). The last two functions allow you to convert between buffers and lists of strings.

Coldmud passes data between the object heirarchy and network connections in terms of buffers; see Connections for details.