fix: missing Bytearray option in file.read_bytes
This commit is contained in:
parent
c8c8b2a023
commit
d9d4d2b305
@ -20,10 +20,10 @@ file.read(path: str) -> str
|
|||||||
Read whole text file.
|
Read whole text file.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
file.read_bytes(path: str) -> array of integers
|
file.read_bytes(path: str, [optional] usetable) -> array of integers
|
||||||
```
|
```
|
||||||
|
|
||||||
Read file into bytes array.
|
Read file into bytes array. If usetable = false , returns Bytearray instead of table.
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
file.is_writeable(path: str) -> bool
|
file.is_writeable(path: str) -> bool
|
||||||
|
|||||||
@ -20,10 +20,10 @@ file.read(путь: str) -> str
|
|||||||
Читает весь текстовый файл и возвращает в виде строки
|
Читает весь текстовый файл и возвращает в виде строки
|
||||||
|
|
||||||
```python
|
```python
|
||||||
file.read_bytes(путь: str) -> array of integers
|
file.read_bytes(путь: str, [опционально] usetable) -> array of integers
|
||||||
```
|
```
|
||||||
|
|
||||||
Читает файл в массив байт.
|
Читает файл в массив байт. При значении usetable = false возвращает Bytearray вместо table.
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
file.is_writeable(путь: str) -> bool
|
file.is_writeable(путь: str) -> bool
|
||||||
|
|||||||
@ -125,14 +125,18 @@ static int l_read_bytes(lua::State* L) {
|
|||||||
if (io::is_regular_file(path)) {
|
if (io::is_regular_file(path)) {
|
||||||
size_t length = static_cast<size_t>(io::file_size(path));
|
size_t length = static_cast<size_t>(io::file_size(path));
|
||||||
|
|
||||||
auto bytes = io::read_bytes(path, length);
|
auto bytes = io::read_bytes(path);
|
||||||
|
|
||||||
lua::createtable(L, length, 0);
|
if (lua::gettop(L) < 2 || !lua::toboolean(L, 2)) {
|
||||||
int newTable = lua::gettop(L);
|
lua::newuserdata<lua::LuaBytearray>(L, std::move(bytes));
|
||||||
|
} else {
|
||||||
|
lua::createtable(L, length, 0);
|
||||||
|
int newTable = lua::gettop(L);
|
||||||
|
|
||||||
for (size_t i = 0; i < length; i++) {
|
for (size_t i = 0; i < length; i++) {
|
||||||
lua::pushinteger(L, bytes[i]);
|
lua::pushinteger(L, bytes[i]);
|
||||||
lua::rawseti(L, i + 1, newTable);
|
lua::rawseti(L, i + 1, newTable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user