add doc/en/scripting/filesystem.md
This commit is contained in:
+5
-98
@@ -390,84 +390,7 @@ hud.get_block_inventory() -> int
|
|||||||
|
|
||||||
Get open block inventory ID or 0
|
Get open block inventory ID or 0
|
||||||
|
|
||||||
## Engine libraries
|
### *time* library
|
||||||
|
|
||||||
### file
|
|
||||||
|
|
||||||
Filesystem interaction library.
|
|
||||||
|
|
||||||
```python
|
|
||||||
file.resolve(path: str) -> str
|
|
||||||
```
|
|
||||||
|
|
||||||
Function turns *entry_point:path* (example *user:worlds/house1*) to a regular path. (example *C://Users/user/.voxeng/worlds/house1*)
|
|
||||||
|
|
||||||
> [!NOTE]
|
|
||||||
> The function should be used for debug only. *entry_point:path* notation is required in all **file** functions.
|
|
||||||
|
|
||||||
Resulting path is not canonical and may be relative.
|
|
||||||
|
|
||||||
```python
|
|
||||||
file.read(path: str) -> str
|
|
||||||
```
|
|
||||||
|
|
||||||
Read whole text file.
|
|
||||||
|
|
||||||
```python
|
|
||||||
file.read_bytes(path: str) -> array of integers
|
|
||||||
```
|
|
||||||
|
|
||||||
Read file into bytes array.
|
|
||||||
|
|
||||||
```python
|
|
||||||
file.write(path: str, text: str) -> nil
|
|
||||||
```
|
|
||||||
|
|
||||||
Overwrite text file.
|
|
||||||
|
|
||||||
```python
|
|
||||||
file.write_bytes(path: str, data: array of integers)
|
|
||||||
```
|
|
||||||
|
|
||||||
Overwrite binary file with bytes array.
|
|
||||||
|
|
||||||
```python
|
|
||||||
file.length(path: str) -> int
|
|
||||||
```
|
|
||||||
|
|
||||||
Get file length (bytes) or 0.
|
|
||||||
|
|
||||||
```python
|
|
||||||
file.exists(path: str) -> bool
|
|
||||||
```
|
|
||||||
|
|
||||||
Check if file or directory exist.
|
|
||||||
|
|
||||||
```python
|
|
||||||
file.isfile(path: str) -> bool
|
|
||||||
```
|
|
||||||
|
|
||||||
Check if the path points to a file.
|
|
||||||
|
|
||||||
```python
|
|
||||||
file.isdir(path: str) -> bool
|
|
||||||
```
|
|
||||||
|
|
||||||
Check if the path points to a directory.
|
|
||||||
|
|
||||||
```python
|
|
||||||
file.mkdir(path: str) -> bool
|
|
||||||
```
|
|
||||||
|
|
||||||
Create directory. Returns true if new directory created
|
|
||||||
|
|
||||||
```python
|
|
||||||
file.mkdirs(path: str) -> bool
|
|
||||||
```
|
|
||||||
|
|
||||||
Create directories chain. Returns true if new directory created
|
|
||||||
|
|
||||||
### time
|
|
||||||
|
|
||||||
```python
|
```python
|
||||||
time.uptime() -> float
|
time.uptime() -> float
|
||||||
@@ -475,24 +398,8 @@ time.uptime() -> float
|
|||||||
|
|
||||||
Returns time elapsed since the engine started.
|
Returns time elapsed since the engine started.
|
||||||
|
|
||||||
## Available modules
|
```python
|
||||||
|
time.delta() -> float
|
||||||
### TOML serialization/deserialization
|
|
||||||
|
|
||||||
```lua
|
|
||||||
local toml = require "core:toml"
|
|
||||||
|
|
||||||
local t = {a=53, b=42, s="test", sub={x=1, y=6}}
|
|
||||||
local s = toml.serialize(t)
|
|
||||||
print(s)
|
|
||||||
local t2 = toml.deserialize(s)
|
|
||||||
```
|
|
||||||
output:
|
|
||||||
```toml
|
|
||||||
b = 42
|
|
||||||
s = "test"
|
|
||||||
a = 53
|
|
||||||
[sub]
|
|
||||||
y = 6
|
|
||||||
x = 1
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Returns time elapsed since the last frame.
|
||||||
|
|||||||
@@ -0,0 +1,89 @@
|
|||||||
|
# Filesystem and serialization
|
||||||
|
|
||||||
|
### *file* library
|
||||||
|
|
||||||
|
Filesystem interaction library.
|
||||||
|
|
||||||
|
```python
|
||||||
|
file.resolve(path: str) -> str
|
||||||
|
```
|
||||||
|
|
||||||
|
Function turns `entry_point:path` (example `user:worlds/house1`) to a regular path. (example `C://Users/user/.voxeng/worlds/house1`)
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
> The function should be used for debug only. *entry_point:path* notation is required in all **file** functions.
|
||||||
|
|
||||||
|
Resulting path is not canonical and may be relative.
|
||||||
|
|
||||||
|
```python
|
||||||
|
file.read(path: str) -> str
|
||||||
|
```
|
||||||
|
|
||||||
|
Read whole text file.
|
||||||
|
|
||||||
|
```python
|
||||||
|
file.read_bytes(path: str) -> array of integers
|
||||||
|
```
|
||||||
|
|
||||||
|
Read file into bytes array.
|
||||||
|
|
||||||
|
```python
|
||||||
|
file.write(path: str, text: str) -> nil
|
||||||
|
```
|
||||||
|
|
||||||
|
Overwrite text file.
|
||||||
|
|
||||||
|
```python
|
||||||
|
file.write_bytes(path: str, data: array of integers)
|
||||||
|
```
|
||||||
|
|
||||||
|
Overwrite binary file with bytes array.
|
||||||
|
|
||||||
|
```python
|
||||||
|
file.length(path: str) -> int
|
||||||
|
```
|
||||||
|
|
||||||
|
Get file length (bytes) or 0.
|
||||||
|
|
||||||
|
```python
|
||||||
|
file.exists(path: str) -> bool
|
||||||
|
```
|
||||||
|
|
||||||
|
Check if file or directory exist.
|
||||||
|
|
||||||
|
```python
|
||||||
|
file.isfile(path: str) -> bool
|
||||||
|
```
|
||||||
|
|
||||||
|
Check if the path points to a file.
|
||||||
|
|
||||||
|
```python
|
||||||
|
file.isdir(path: str) -> bool
|
||||||
|
```
|
||||||
|
|
||||||
|
Check if the path points to a directory.
|
||||||
|
|
||||||
|
```python
|
||||||
|
file.mkdir(path: str) -> bool
|
||||||
|
```
|
||||||
|
|
||||||
|
Create directory. Returns true if new directory created
|
||||||
|
|
||||||
|
```python
|
||||||
|
file.mkdirs(path: str) -> bool
|
||||||
|
```
|
||||||
|
|
||||||
|
Create directories chain. Returns true if new directory created.
|
||||||
|
|
||||||
|
## Storing data in a world
|
||||||
|
|
||||||
|
When saving pack data in the world, you should use the function:
|
||||||
|
|
||||||
|
```python
|
||||||
|
pack.data_file(packid: str, filename: str) -> str
|
||||||
|
```
|
||||||
|
|
||||||
|
Returns data file path like: `world:data/packid/filename`
|
||||||
|
and creates missing directories.
|
||||||
|
|
||||||
|
If paths other than `data/{packid}/...` are used, data may be lost.
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
|
# Файловая система и сериализация
|
||||||
|
|
||||||
## Библиотека *file*
|
## Библиотека *file*
|
||||||
|
|
||||||
Библиотека функций для работы с файлами
|
Библиотека функций для работы с файлами
|
||||||
|
|
||||||
```python
|
```python
|
||||||
file.resolve(путь: str) -> str
|
file.resolve(путь: str) -> str
|
||||||
```
|
```
|
||||||
|
|
||||||
Функция приводит запись `точка_входа:путь` (например `user:worlds/house1`) к обычному пути. (например `C://Users/user/.voxeng/worlds/house1`)
|
Функция приводит запись `точка_входа:путь` (например `user:worlds/house1`) к обычному пути. (например `C://Users/user/.voxeng/worlds/house1`)
|
||||||
|
|
||||||
@@ -127,11 +129,10 @@ toml.parse(code: str) -> table
|
|||||||
|
|
||||||
При сохранении данных пака в мире следует использовать функцию
|
При сохранении данных пака в мире следует использовать функцию
|
||||||
```python
|
```python
|
||||||
pack.data_file(packid: str, filename: str) -> str
|
pack.data_file(id_пака: str, имя_файла: str) -> str
|
||||||
```
|
```
|
||||||
|
|
||||||
Функция возвращает путь к файлу данных по типу: `world:data/packid/filename`
|
Функция возвращает путь к файлу данных по типу: `world:data/id_пака/имя_файла`
|
||||||
|
|
||||||
и создает недостающие директории в пути.
|
и создает недостающие директории в пути.
|
||||||
|
|
||||||
При использовании путей не соответствующим `data/{packid}/...` возможна потеря данных при перезаписи мира.
|
При использовании путей не соответствующим `data/{packid}/...` возможна потеря данных при перезаписи мира.
|
||||||
|
|||||||
Reference in New Issue
Block a user