add unpack function documentation
This commit is contained in:
parent
ee26b2a2b9
commit
72394181c7
@ -39,6 +39,12 @@ Value characters describe the type and size.
|
||||
> [!WARNING]
|
||||
> Due to the absence of an integer type in Lua for values `l` and `L`, only an output size of 8 bytes is guaranteed; the value may differ from what is expected.
|
||||
|
||||
```lua
|
||||
byteutil.unpack(format: str, bytes: table|Bytearray) -> ...
|
||||
```
|
||||
|
||||
Extracts values from a byte array based on a format string.
|
||||
|
||||
Example:
|
||||
|
||||
```lua
|
||||
@ -58,14 +64,7 @@ debug.print(byteutil.tpack('>iBH?', -8, 250, 2019, true))
|
||||
-- )
|
||||
|
||||
local bytes = byteutil.pack('>iBH?', -8, 250, 2019, true)
|
||||
debug.print(byteutil.unpack('>iBH?', bytes))
|
||||
print(byteutil.unpack('>iBH?', bytes))
|
||||
-- outputs:
|
||||
-- debug.print(
|
||||
-- {
|
||||
-- -8,
|
||||
-- 250,
|
||||
-- 2019,
|
||||
-- true
|
||||
-- }
|
||||
--)
|
||||
-- -8 250 2019 true
|
||||
```
|
||||
|
||||
@ -40,6 +40,12 @@ byteutil.tpack(format: str, ...) -> table
|
||||
> Из-за отсутствия в Lua целочисленного типа для значений `l` и `L` гарантируется
|
||||
> только выходной размер в 8 байт, значение может отличаться от ожидаемого.
|
||||
|
||||
```lua
|
||||
byteutil.unpack(format: str, bytes: table|Bytearray) -> ...
|
||||
```
|
||||
|
||||
Извлекает значения из массива байт, ориентируясь на строку формата.
|
||||
|
||||
Пример:
|
||||
|
||||
```lua
|
||||
|
||||
@ -134,8 +134,6 @@ static int l_unpack(lua::State* L) {
|
||||
ByteReader reader(bytes);
|
||||
bool bigEndian = false;
|
||||
|
||||
int index = 1;
|
||||
lua::createtable(L, count, 0);
|
||||
for (size_t i = 0; format[i]; i++) {
|
||||
switch (format[i]) {
|
||||
case 'b':
|
||||
@ -185,9 +183,8 @@ static int l_unpack(lua::State* L) {
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
lua::rawseti(L, index++);
|
||||
}
|
||||
return 1;
|
||||
return count;
|
||||
}
|
||||
|
||||
static int l_pack(lua::State* L) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user