diff --git a/doc/en/scripting.md b/doc/en/scripting.md index 2c8ddc1a..f9467336 100644 --- a/doc/en/scripting.md +++ b/doc/en/scripting.md @@ -8,7 +8,7 @@ Subsections: - [Filesystem and serialization](scripting/filesystem.md) - [Module core:bit_converter](scripting/modules/core_bit_converter.md) - [Module core:data_buffer](scripting/modules/core_data_buffer.md) -- [Module core:Vector2, core:Vector3](scripting/modules/core_Vector2&&Vector3.md) +- [Module core:vector2, core:vector3](scripting/modules/core_vector2_vector3.md) ## Core functions diff --git a/doc/en/scripting/modules/core_bit_converter.md b/doc/en/scripting/modules/core_bit_converter.md new file mode 100644 index 00000000..822c1394 --- /dev/null +++ b/doc/en/scripting/modules/core_bit_converter.md @@ -0,0 +1,93 @@ +# Module core:bit_converter + +## Converting values ​​to bytes and back + +```lua +function bit_converter.string_to_bytes(string: str) -> table +``` +Converts a string to bytes + +```lua +function bit_converter.bool_to_byte(boolean: bool) -> integer +``` +Converts a boolean to a byte + +```lua +function bit_converter.single_to_bytes(number: single) -> table +``` +Converts a single precision float value to bytes + +```lua +function bit_converter.double_to_bytes(number: double) -> table +``` +Converts a double precision float value to bytes + +```lua +function bit_converter.uint16_to_bytes(integer: int) -> table +``` +Converts an unsigned 2-bytes integer to bytes + +```lua +function bit_converter.uint32_to_bytes(integer: int) -> table +``` +Converts an unsigned 4-bytes integer to bytes + +```lua +function bit_converter.int16_to_bytes(integer: int) -> table +``` +Converts a signed 2-bytes integer to bytes + +```lua +function bit_converter.int32_to_bytes(integer: int) -> table +``` +Converts a signed 4-bytes integer to bytes + +```lua +function bit_converter.int64_to_bytes(integer: int) -> table +``` +Converts a signed 8-bytes integer to bytes + +```lua +function bit_converter.bytes_to_string(table: bytes) -> string +``` +Converts a byte array to a string + +```lua +function bit_converter.byte_to_bool(integer: byte) -> boolean +``` +Converts a byte to a boolean value + +```lua +function bit_converter.bytes_to_single(table: bytes) -> number№ +``` +Converts a byte array to a single-precision float + +```lua +function bit_converter.bytes_to_double(table: bytes) -> number +``` +Converts a byte array to a double precision float + +```lua +function bit_converter.bytes_to_uint16(table: bytes) -> integer +``` +Converts a byte array to a 2-bytes unsigned number + +```lua +function bit_converter.bytes_to_uint32(table: bytes) -> integer +``` +Converts a byte array to a 4-bytes unsigned number + +```lua +function bit_converter.bytes_to_int16(table: bytes) -> integer +``` +Converts a byte array to a 2-bytes signed number + +```lua +function bit_converter.bytes_to_int32(table: bytes) -> integer +``` +Converts a byte array to a 4-bytes signed number + +```lua +function bit_converter.bytes_to_int64(table: bytes) -> integer +``` +Converts a byte array to an 8-bytes signed number diff --git a/doc/en/scripting/modules/core_data_buffer.md b/doc/en/scripting/modules/core_data_buffer.md new file mode 100644 index 00000000..fe383579 --- /dev/null +++ b/doc/en/scripting/modules/core_data_buffer.md @@ -0,0 +1,155 @@ +# Module core:data_buffer + +## Data buffer +### Stores an array of bytes and allows you to easily get or add different values + +```lua +function data_buffer(bytes) +``` +Creates a new data_buffer instance (the bytes parameter is optional) + +```lua +function data_buffer:put_byte(integer: byte) +``` +Writes a byte to the buffer + +```lua +function data_buffer:put_bytes(table: bytes) +``` +Writes bytes to the buffer + +```lua +function data_buffer:put_string(string: str) +``` +Converts a string to bytes and writes them to the buffer + +```lua +function data_buffer:put_bool(boolean: bool) +``` +Converts a boolean value to a byte and writes it to the buffer + +```lua +function data_buffer:put_single(number: single) +``` +Converts a single precision float to bytes and writes them to the buffer + +```lua +function data_buffer:put_double(number: double) +``` +Converts a double precision float to bytes and writes them to the buffer + +```lua +function data_buffer:put_uint16(integer: int) +``` +Converts an unsigned 2-bytes number to bytes and writes them to the buffer + +```lua +function data_buffer:put_uint32(integer: int) +``` +Converts an unsigned 4-bytes number to bytes and writes them to the buffer + +```lua +function data_buffer:put_int16(integer: int) +``` +Converts a signed 2-bytes number into bytes and writes them to the buffer + +```lua +function data_buffer:put_int32(integer: int) +``` +Converts a signed 4-bytes number into bytes and writes them to the buffer + +```lua +function data_buffer:put_int64(integer: int) +``` +Converts a signed 8-bytes number to bytes and writes them to the buffer + +```lua +function data_buffer:put_number(number: num) +``` +Converts any number into bytes and writes them to the buffer; + +The first byte is the value type: +```lua +zero = 0 +uint16 = 1 +uint32 = 2 +int16 = 3 +int32 = 4 +int64 = 5 +double = 6 +``` + +```lua +function data_buffer:get_byte() -> integer +``` +Returns the next byte from the buffer + +```lua +function data_buffer:get_bytes(n) -> table +``` +Returns the next n bytes, if n is nil or not specified, then an array of all bytes is returned + +```lua +function data_buffer:get_string() -> string +``` +Reads the next line from the buffer + +```lua +function data_buffer:get_bool() -> boolean +``` +Reads the next Boolean from the buffer + +```lua +function data_buffer:get_single() -> number +``` +Reads the next single precision floating number from the buffer + +```lua +function data_buffer:get_double() -> number +``` +Reads the next double precision floating number from the buffer + +```lua +function data_buffer:get_uint16() -> integer +``` +Reads the next 2-bytes unsigned integer from the buffer + +```lua +function data_buffer:get_uint32() -> integer +``` +Reads the next 4-bytes unsigned integer from the buffer + +```lua +function data_buffer:get_int16() -> integer +``` +Reads the next 2-bytes signed integer from the buffer + +```lua +function data_buffer:get_int32() -> integer +``` +Reads the next 4-bytes signed integer from the buffer + +```lua +function data_buffer:get_int64() -> integer +``` +Reads the next 8-bytes signed integer from the buffer + +```lua +function data_buffer:get_number() -> number +``` +Reads the next number (see data_buffer:put_number) + +```lua +function data_buffer:size() -> integer +``` +Returns the buffer size + +```lua +function data_buffer:set_position(integer: pos) +``` +Sets the current position in the buffer + +```lua +function data_buffer:set_bytes(table: bytes) +``` +Sets bytes into the buffer diff --git a/doc/en/scripting/modules/core_vector2_vector3.md b/doc/en/scripting/modules/core_vector2_vector3.md new file mode 100644 index 00000000..4c545739 --- /dev/null +++ b/doc/en/scripting/modules/core_vector2_vector3.md @@ -0,0 +1,191 @@ +# Modules core:vector2, core:vector3 + +## Vector2 +### Operations on vectors + + +```lua +function vector2:round(decimals: number) -> round[vec2] +``` +Rounding vector components + +```lua +function vector2:len() -> number +``` +Vector length + +```lua +function vector2:norm() -> number +``` +Vector normalization + +```lua +function vector2:abtw(vector: vec2) -> number +``` +Angle between two vectors in radians + +```lua +function vector2:proj(vector: vec2) -> vec2 +``` +Vector projection + +```lua +function vector2:dot(vector: vec2) -> number +``` +Vector (internal) product + +```lua +function vector2:lerp( + --Target vector + b:vec2, + --Interpolation coefficient (0 to 1) + t:number + ) -> vec2 +``` +Linear vector interpolation + +```lua +function vector2:dist(vector: vec2) -> number +``` +Distance between two vectors + +```lua +function vector2:cross(vector: vec2) -> number +``` +Vector (external) product + +```lua +function vector2:rot( + --The angle of rotation of the vector at a given angle (in radians) + angle: number->rad, + --Rotation of the vector relative to the axes ("x", "y", "z") + axis: str, + --If true, then the rotation angle is converted automatically from degrees to radians + convert2deg:bool + ) -> vec2 +``` +Rotate a vector + +### Operations with vectors + +```lua + local vec2 = require("core:vector2") + + local v1 = vec2(5, 10) + local v2 = vec2(10, 15) + + -- vec2 .. vec2 + sum_vectors = v1 + v2 -- (15, 25) + sub_vectors = v1 - v2 -- (-5, -5) + mul_vectors = v1 * v2 -- (50, 150) + div_vectors = v1 / v2 -- (0.5, 0.66667.) + pow_vectors = v1 ^ v2 -- (9765625, 1e+15) + + --vec2 .. scalar + sum_vec2_scalar = v1 + 10 -- (15, 25) + sub_vec2_scalar = v1 - 12 -- (-7, -2) + mul_vec2_scalar = v1 * 20 -- (100, 200) + div_vec2_scalar = v1 / 1 -- (5, 10) + pow_vec2_scalar= v1 ^ 2 -- (25, 100) +``` + + + +## Vector3 +### Operations on vectors + +```lua +function vector3:round(decimals: number) -> round[vec3] +``` +Rounding vector components +```lua +function vector3:len() -> number +``` +Vector length + +```lua +function vector3:norm() -> number +``` +Vector normalization + +```lua +function vector3:abtw(vector: vec3) -> number +``` +Angle between two vectors in radians + +```lua +function vector3:isParallel(vector: vec3) -> bool +``` +Parallelism of a vector to another vector + + +```lua +function vector3:proj(vector: vec3) -> vec3 +``` +Vector projection +... + +```lua +function vector3:dot(vector: vec3) -> number +``` +Vector (internal) product + +```lua +function vector3:lerp( + --Target vector + b:vec3, + --Interpolation coefficient (0 to 1) + t:number + ) -> vec3 +``` +Linear vector interpolation + +```lua +function vector3:dist(vector: vec3) -> number +``` +Distance between two vectors + +```lua +function vector3:dist2line(point1: vec3, point2: vec3) -> number +``` +Distance to line + +```lua +function vector3:cross(vector: vec3) -> number +``` +Vector (external) product + +```lua +function vector3:rot( + --The angle of rotation of the vector at a given angle (in radians) + angle: number->rad, + --Rotation of the vector relative to the axes ("x", "y", "z") + axis: str, + --If true, then the rotation angle is converted automatically from degrees to radians + convert2deg:bool + ) -> vec2 +``` +Rotate a vector + +### Operations with vectors + +```lua + +local vec3 = require("core:vector3") + +local v1 = vec3(1, 2, 3) +local v2 = vec3(4, 5, 6) + +--vec3..vec3 +local sum_vectors = v1 + v2 -- (5, 7, 9) +local sub_vectors = v1 - v2 -- (-3, -3, -3) +local mul_vectors = v1 * v2 -- (4, 10, 18) +local div_vectors = v1 / v2 -- (0.25, 0.4, 0.5) +local pow_vectors = v1 ^ v2 -- (1, 32, 216) + +--vec3..scalar +local scalar_vector = v1 * 2 -- (2, 4, 6) +local scalar_number = 2 * v1 -- (2, 4, 6) +-- ..etc + +``` diff --git a/doc/ru/scripting.md b/doc/ru/scripting.md index e78a95ec..a6834591 100644 --- a/doc/ru/scripting.md +++ b/doc/ru/scripting.md @@ -8,7 +8,7 @@ - [Файловая система и сериализация](scripting/filesystem.md) - [Модуль core:bit_converter](scripting/modules/core_bit_converter.md) - [Модуль core:data_buffer](scripting/modules/core_data_buffer.md) -- [Модули core:Vector2, core:Vector3](scripting/modules/core_Vector2&&Vector3.md) +- [Модули core:vector2, core:vector3](scripting/modules/core_vector2_vector3.md) ```lua diff --git a/doc/ru/scripting/modules/core_bit_converter.md b/doc/ru/scripting/modules/core_bit_converter.md index cf2126c6..f9930560 100644 --- a/doc/ru/scripting/modules/core_bit_converter.md +++ b/doc/ru/scripting/modules/core_bit_converter.md @@ -1,3 +1,5 @@ +# Модуль core:bit_converter + ## Конвертация значений в байты и обратно ```lua @@ -23,27 +25,27 @@ function bit_converter.double_to_bytes(number: double) -> table ```lua function bit_converter.uint16_to_bytes(integer: int) -> table ``` -Конвертирует беззнаковое 2-х битное целое число в байты +Конвертирует беззнаковое 2-х байтовое целое число в байты ```lua function bit_converter.uint32_to_bytes(integer: int) -> table ``` -Конвертирует беззнаковое 4-х битное целое число в байты +Конвертирует беззнаковое 4-х байтовое целое число в байты ```lua function bit_converter.int16_to_bytes(integer: int) -> table ``` -Конвертирует знаковое 2-х битное целое число в байты +Конвертирует знаковое 2-х байтовое целое число в байты ```lua function bit_converter.int32_to_bytes(integer: int) -> table ``` -Конвертирует знаковое 4-х битное целое число в байты +Конвертирует знаковое 4-х байтовое целое число в байты ```lua function bit_converter.int64_to_bytes(integer: int) -> table ``` -Конвертирует знаковое 8-и битное целое число в байты +Конвертирует знаковое 8-и байтовое целое число в байты ```lua function bit_converter.bytes_to_string(table: bytes) -> string @@ -68,24 +70,24 @@ function bit_converter.bytes_to_double(table: bytes) -> number ```lua function bit_converter.bytes_to_uint16(table: bytes) -> integer ``` -Конвертирует массив байтов в 2-х битное беззнаковое число +Конвертирует массив байтов в 2-х байтовое беззнаковое число ```lua function bit_converter.bytes_to_uint32(table: bytes) -> integer ``` -Конвертирует массив байтов в 4-х битное беззнаковое число +Конвертирует массив байтов в 4-х байтовое беззнаковое число ```lua function bit_converter.bytes_to_int16(table: bytes) -> integer ``` -Конвертирует массив байтов в 2-х битное знаковое число +Конвертирует массив байтов в 2-х байтовое знаковое число ```lua function bit_converter.bytes_to_int32(table: bytes) -> integer ``` -Конвертирует массив байтов в 4-х битное знаковое число +Конвертирует массив байтов в 4-х байтовое знаковое число ```lua function bit_converter.bytes_to_int64(table: bytes) -> integer ``` -Конвертирует массив байтов в 8-х битное знаковое число \ No newline at end of file +Конвертирует массив байтов в 8-х байтовое знаковое число diff --git a/doc/ru/scripting/modules/core_data_buffer.md b/doc/ru/scripting/modules/core_data_buffer.md index 4bbbacf6..60c36193 100644 --- a/doc/ru/scripting/modules/core_data_buffer.md +++ b/doc/ru/scripting/modules/core_data_buffer.md @@ -1,3 +1,5 @@ +# Модуль core:data_buffer + ## Буффер данных ### Хранит в себе массив байтов и позволяет легко получать или добавлять разные значения @@ -39,27 +41,27 @@ function data_buffer:put_double(number: double) ```lua function data_buffer:put_uint16(integer: int) ``` -Конвертирует беззнаковое 2-х битное число в байты и записывает их в буффер +Конвертирует беззнаковое 2-х байтовое число в байты и записывает их в буффер ```lua function data_buffer:put_uint32(integer: int) ``` -Конвертирует беззнаковое 4-х битное число в байты и записывает их в буффер +Конвертирует беззнаковое 4-х байтовое число в байты и записывает их в буффер ```lua function data_buffer:put_int16(integer: int) ``` -Конвертирует знаковое 2-х битное число в байты и записывает их в буффер +Конвертирует знаковое 2-х байтовое число в байты и записывает их в буффер ```lua function data_buffer:put_int32(integer: int) ``` -Конвертирует знаковое 4-х битное число в байты и записывает их в буффер +Конвертирует знаковое 4-х байтовое число в байты и записывает их в буффер ```lua function data_buffer:put_int64(integer: int) ``` -Конвертирует знаковое 8-и битное число в байты и записывает их в буффер +Конвертирует знаковое 8-и байтовое число в байты и записывает их в буффер ```lua function data_buffer:put_number(number: num) @@ -110,27 +112,27 @@ function data_buffer:get_double() -> number ```lua function data_buffer:get_uint16() -> integer ``` -Читает следующее 2-х битное беззнаковое целое число из буффера +Читает следующее 2-х байтовое беззнаковое целое число из буффера ```lua function data_buffer:get_uint32() -> integer ``` -Читает следующее 4-х битное беззнаковое целое число из буффера +Читает следующее 4-х байтовое беззнаковое целое число из буффера ```lua function data_buffer:get_int16() -> integer ``` -Читает следующее 2-х битное знаковое целое число из буффера +Читает следующее 2-х байтовое знаковое целое число из буффера ```lua function data_buffer:get_int32() -> integer ``` -Читает следующее 4-х битное знаковое целое число из буффера +Читает следующее 4-х байтовое знаковое целое число из буффера ```lua function data_buffer:get_int64() -> integer ``` -Читает следующее 8-х битное знаковое целое число из буффера +Читает следующее 8-х байтовое знаковое целое число из буффера ```lua function data_buffer:get_number() -> number @@ -150,4 +152,4 @@ function data_buffer:set_position(integer: pos) ```lua function data_buffer:set_bytes(table: bytes) ``` -Устанавливает байты в буффер \ No newline at end of file +Устанавливает байты в буффер diff --git a/doc/ru/scripting/modules/core_Vector2&&Vector3.md b/doc/ru/scripting/modules/core_vector2_vector3.md similarity index 97% rename from doc/ru/scripting/modules/core_Vector2&&Vector3.md rename to doc/ru/scripting/modules/core_vector2_vector3.md index a1ea4d1c..349e5858 100644 --- a/doc/ru/scripting/modules/core_Vector2&&Vector3.md +++ b/doc/ru/scripting/modules/core_vector2_vector3.md @@ -1,4 +1,5 @@ -# Вектора +# Модули core:vector2, core:vector3 + ## Vector2 ### Операции над векторами @@ -7,6 +8,7 @@ function vector2:round(decimals: number) -> round[vec2] ``` Округление компонентов вектора + ```lua function vector2:len() -> number ``` @@ -68,7 +70,7 @@ function vector2:rot( ### Операции с векторами ```lua - local vec2 = require("res:vector2") + local vec2 = require("core:vector2") local v1 = vec2(5, 10) local v2 = vec2(10, 15) @@ -170,7 +172,7 @@ function vector3:rot( ```lua -local vec3 = require("res:vector3") +local vec3 = require("core:vector3") local v1 = vec3(1, 2, 3) local v2 = vec3(4, 5, 6)