Skip to content

Commit

Permalink
add doc/en/scripting/modules/*
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailRis committed Jun 13, 2024
1 parent 92cc208 commit d057f68
Show file tree
Hide file tree
Showing 8 changed files with 471 additions and 26 deletions.
2 changes: 1 addition & 1 deletion doc/en/scripting.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
93 changes: 93 additions & 0 deletions doc/en/scripting/modules/core_bit_converter.md
Original file line number Diff line number Diff line change
@@ -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
155 changes: 155 additions & 0 deletions doc/en/scripting/modules/core_data_buffer.md
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit d057f68

Please sign in to comment.