buffer_write

语法:

buffer_write(buffer, type, value)


参数 描述
buffer The index of the buffer to write to.
type The type of data that is to be written to the buffer (see the list of constants below).
要写入的数据。


Returns: 0 if success, or one of the following constants if it fails:

常量 描述
buffer_generalerror is given when writing to a buffer with a string and the string is empty or the value is not a string
buffer_outofspace is returned when reading / writing to a buffer beyond its capacity
buffer_outofbounds is when an explicit operation is outside of the buffer capacity (i.e. index is < 0 or > capacity)
buffer_invalidtype is when a non u8 type is used for writing to a fast buffer type.


描述

This function can be used to write data to a previously created buffer. The data you write must be in agreement with the "type" argument of this function, meaning that you can't try to write a string as an unsigned 16bit integer, for example. The following constants can be used to define the data type:

常量 描述
buffer_u8 无符号 8 位整型。值域为 0 到 255。
buffer_s8 有符号 8 位整型。值域为 -128 到 127(0为正数)。
buffer_u16 无符号 16 位整型。值域为 0 到 65535 。
buffer_s16 有符号 16 位整型。值域为 -32768 到 32767(0为正数)。
buffer_u32 无符号 32 位整型。值域为 0 到 4,294,967,295。
buffer_s32 有符号 32 位整形。值域为 -2,147,483,648 到 2,147,483,647(0为正数)。
buffer_u64 An unsigned 64bit integer.
buffer_f16 A 16bit float. This can be a positive or negative value within the same range as a 16 bit signed integer.
buffer_f32 A 32bit float. This can be a positive or negative value within the same range as a 32 bit signed integer.
buffer_f64 A 64bit float.
buffer_bool 布尔类型。只能为 1 或 0 (truefalse)
buffer_string A string of any size, finalized with a null terminating character.
buffer_text A string of any size, without the final null terminating character.


例如:

buffer_seek(buff, buffer_seek_start, 0);
buffer_write(buff, buffer_s16, 0);
buffer_write(buff, buffer_s16, x);
buffer_write(buff, buffer_s16, y);

The above code finds the start of the buffer with the id stored in the variable "buff" them writes a series of signed 16bit integer values to it.