diff --git a/.github/workflows/matlab.yml b/.github/workflows/matlab.yml new file mode 100644 index 0000000..abbf6a5 --- /dev/null +++ b/.github/workflows/matlab.yml @@ -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 diff --git a/src/main.cpp b/src/main.cpp index d50bce7..f4dde68 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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) { @@ -35,6 +44,11 @@ PYBIND11_MODULE(cmake_example, m) { Some other explanation about the subtract function. )pbdoc"); + py::class_(m, "AStruct", py::metaclass((PyObject *) &PyType_Type)).def(py::init<>()); + py::class_(m, "BStruct", py::metaclass((PyObject *) &PyType_Type)).def(py::init()); + + m.def("fun", [](AStruct &a) { return 44; }, "doc", py::arg("a") ); + #ifdef VERSION_INFO m.attr("__version__") = MACRO_STRINGIFY(VERSION_INFO); #else diff --git a/tests/test_basic.py b/tests/test_basic.py index 070626e..f00045f 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -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)