Compare commits

..

No commits in common. "378def9360df28c7b2205d48ba191ae7e0e0b3fd" and "51b14d35261a98c86a30204be1c1e39f29e3fd69" have entirely different histories.

6 changed files with 126 additions and 7 deletions

View File

@ -5,6 +5,15 @@ label: array2d
Efficient general-purpose 2D array.
#### Source code
https://github.com/pocketpy/pocketpy/blob/main/include/typings/array2d.pyi
:::code source="../../include/typings/array2d.pyi" :::
## Example
```python
from array2d import array2d
a = array2d(3, 4, default=0)
a[1, 2] = 5
print(a[1, 2]) # 5
```

View File

@ -11,6 +11,4 @@ A decorator that is used to add special method to classes, including `__init__`,
Convert a dataclass instance to a dictionary.
#### Source code
:::code source="../../python/dataclasses.py" :::

42
docs/modules/io.md Normal file
View File

@ -0,0 +1,42 @@
---
icon: package-dependencies
label: io
---
!!!
This module is optional. Set `PK_ENABLE_OS` to `1` to enable it.
!!!
### `io.FileIO.read(size=-1) -> bytes | str`
Read up to `size` bytes from the file. If `size` is negative or omitted, read until EOF.
### `io.FileIO.write(data: bytes | str)`
Write the given data to the file.
### `io.FileIO.seek(offset, whence=0) -> int`
Change the file position to the given offset. The `whence` argument is optional and defaults to `0` (absolute file positioning); other values are `1` (seek relative to the current position) and `2` (seek relative to the file's end).
### `io.FileIO.tell() -> int`
Return the current file position.
### `io.FileIO.close()`
Close the file.
### `io.SEEK_SET`
Seek from the beginning of the file.
### `io.SEEK_CUR`
Seek from the current position.
### `io.SEEK_END`
Seek from the end of the file.

View File

@ -7,6 +7,6 @@ Provide `mat3x3`, `vec2`, `vec3` and `vec4` types.
This classes adopt `torch`'s naming convention. Methods with `_` suffix will modify the instance itself.
#### Source code
https://github.com/pocketpy/pocketpy/blob/main/include/typings/linalg.pyi
:::code source="../../include/typings/linalg.pyi" :::

72
docs/modules/os.md Normal file
View File

@ -0,0 +1,72 @@
---
icon: package-dependencies
label: os
---
!!!
This module is optional. Set `PK_ENABLE_OS` to `1` to enable it.
!!!
### `os.getcwd()`
Returns the current working directory.
### `os.chdir(path: str)`
Changes the current working directory to the given path.
### `os.listdir(path: str)`
Returns a list of files and directories in the given path.
### `os.remove(path: str)`
Removes the file at the given path.
### `os.mkdir(path: str)`
Creates a directory at the given path.
### `os.rmdir(path: str)`
Removes the directory at the given path.
### `os.path.join(*paths: str)`
Joins the given paths together.
### `os.path.exists(path: str)`
Check if the given path exists.
### `os.path.basename(path: str)`
Returns the basename of the given path.
### `os.path.isdir(path: str)`
Check if the given path is a directory.
### `os.path.isfile(path: str)`
Check if the given path is a file.
### `os.path.abspath(path: str)`
Returns the absolute path of the given path.
## Other functions
You can add other functions to `os` module via normal binding if you need them.
For example, add `os.system`:
```cpp
PyVar mod = vm->_modules["os"];
vm->bind(mod, "system(cmd: str) -> int", [](VM* vm, ArgsView args){
const char* cmd = py_cast<CString>(vm, args[0]);
int code = system(cmd);
return py_var(vm, code);
});
```

View File

@ -5,6 +5,4 @@ label: typing
Placeholder module for type hints.
#### Source code
:::code source="../../python/typing.py" :::