Skip to content
Open
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
51 changes: 51 additions & 0 deletions .github/workflows/matlab.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: matlab

defaults:
run:
shell: bash

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]



jobs:
matlab:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2
with:
submodules: recursive

- uses: actions/setup-python@v1
with:
python-version: 3.8

- run: |
echo "CC=gcc-9" >> $GITHUB_ENV
echo "CXX=g++-9" >> $GITHUB_ENV
VERBOSE=1 pip install --verbose -e .

- run: |
echo "m = py.importlib.import_module('cmake_example')" > test.m
echo "AStruct = m.AStruct" >> test.m
echo "AStruct()" >> test.m
cat test.m

- run: python -c "import cmake_example as m; m.AStruct()"

#- run: |
# echo "pybind11_type=type" > pybind11_builtins.py
# echo "PYTHONPATH=." >> $GITHUB_ENV

- uses: matlab-actions/setup-matlab@v0
with:
release: R2022a

- uses: matlab-actions/run-command@v0
with:
command: test
14 changes: 14 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ int add(int i, int j) {
return i + j;
}

struct AStruct {
AStruct() {
}
};
struct BStruct {
BStruct(AStruct &a) {
}
};

namespace py = pybind11;

PYBIND11_MODULE(cmake_example, m) {
Expand Down Expand Up @@ -35,6 +44,11 @@ PYBIND11_MODULE(cmake_example, m) {
Some other explanation about the subtract function.
)pbdoc");

py::class_<AStruct>(m, "AStruct", py::metaclass((PyObject *) &PyType_Type)).def(py::init<>());
py::class_<BStruct>(m, "BStruct", py::metaclass((PyObject *) &PyType_Type)).def(py::init<AStruct&>());

m.def("fun", [](AStruct &a) { return 44; }, "doc", py::arg("a") );

#ifdef VERSION_INFO
m.attr("__version__") = MACRO_STRINGIFY(VERSION_INFO);
#else
Expand Down
5 changes: 5 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ def test_main():
assert m.__version__ == "0.0.1"
assert m.add(1, 2) == 3
assert m.subtract(1, 2) == -1

a = m.AStruct()
assert a is not None
m.fun(a)
b = m.BStruct(a)