Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The old emscripten 3.1.73 based branch is available at https://github.com/emscri
pyjs is modern [pybind11](https://github.com/pybind/pybind11) + emscripten [Embind](https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html) based
Python <-> JavaScript foreign function interface (FFI) for wasm/emscripten compiled Python.

The API is loosly based on the FFI of [pyodide](https://pyodide.org/en/stable/usage/type-conversions.html).
The API is loosely based on the FFI of [pyodide](https://pyodide.org/en/stable/usage/type-conversions.html).

## Full Documentation
See the [documentation](https://emscripten-forge.github.io/pyjs/) for a full documentation.
Expand All @@ -31,7 +31,7 @@ Access Javascript from Python:
```python
import pyjs

# hello world
# hello world
pyjs.js.console.log("Hello, World!")

# create a JavaScript function to add two numbers
Expand All @@ -44,7 +44,7 @@ js_function = pyjs.js.Function("a", "b", """
result = js_function(1, 2)
```

Access Python from Javascript:
Access Python from JavaScript:

```JavaScript
// hello world
Expand All @@ -53,6 +53,6 @@ pyjs.eval("print('Hello, World!')")
// eval a python expression and get the result
const py_list = pyjs.eval("[i for i in range(10)]")

/// access
// access
console.log(py_list.get(0)) // same as py_list[0] on the python side
```
1 change: 1 addition & 0 deletions src/export_js_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ namespace pyjs


py::class_<TypedArrayBuffer>(m, "TypedArrayBuffer", py::buffer_protocol())
.def("__len__", [](const TypedArrayBuffer& self) { return self.m_size; })
.def_buffer([](TypedArrayBuffer& self) -> py::buffer_info
{
return py::buffer_info(self.m_data, self.m_bytes_per_element, self.m_format_descriptor,
Expand Down
12 changes: 12 additions & 0 deletions tests/tests/test_pyjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,18 @@ def test_to_py(test_input, expected_type, expected_value, comperator):
assert comperator(py_val, expected_value)


@pytest.mark.parametrize(
"test_input,expected_length",
[
("new Uint8Array([1,2,3])", 3),
("new Uint16Array([1,2,3,4])", 4),
("new Float64Array([])", 0),
],
)
def test_typed_array_buffer_len(test_input, expected_length):
assert len(pyjs.to_py(ensure_js(test_input))) == expected_length


@pytest.mark.parametrize(
"test_input",
[
Expand Down
Loading