SWIG (or similar wrapping tool) support?

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
stijn
Posts: 735
Joined: Thu Apr 24, 2014 9:13 am

Re: SWIG (or similar wrapping tool) support?

Post by stijn » Tue Dec 15, 2015 8:46 pm

pfalcon wrote: Other approach is just to provide some manual, but simplified API for wrapping function - most realistically, "simplification" would require C++ usage, as e.g. Boost.Python does.
Explained that here: http://forum.micropython.org/viewtopic. ... =791#p4592, module creation and function registration goes like https://github.com/stinos/micropython/b ... in.cpp#L33.
Note for CPython there's now also https://github.com/wjakob/pybind11 which has similar syntax and might be more attractive than Boost.Python, mainly because it does not use boost. I quickly looked into it but adapting it to work with uPy would almost come down to complete rewrite from scratch.

igorgatis
Posts: 21
Joined: Thu Nov 19, 2015 1:10 pm

Re: SWIG (or similar wrapping tool) support?

Post by igorgatis » Wed Dec 16, 2015 2:04 pm

Let's say I find a good mechanism (be it through Clang or SWIG's XML) to generate micropython bindings. According to dhylands orientation, the generated binding needs to be "registered" as a builtin module. Is that the only way to go? Builtin modules?

I guess that's almost by design since the port has so many important knobs (e.g. MICROPY_OBJ_REPR) that the module needs to be compiled together with micropython. IOW, all statically linked and no shared libraries.

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: SWIG (or similar wrapping tool) support?

Post by pfalcon » Wed Dec 16, 2015 4:14 pm

Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

igorgatis
Posts: 21
Joined: Thu Nov 19, 2015 1:10 pm

Re: SWIG (or similar wrapping tool) support?

Post by igorgatis » Wed Dec 16, 2015 8:10 pm

Say C function looks like this:

Code: Select all

int SetCallBacks(void (*A)(void), void (*B)(char *), int (*C)(char **, int, int, int *))
1. What the C code for SetCallBacks should look like?

2. What the Python code for callbacks A, B and C should look like?


pmp-p
Posts: 13
Joined: Mon Apr 24, 2017 12:45 am

Re: SWIG (or similar wrapping tool) support?

Post by pmp-p » Wed Sep 25, 2019 11:55 pm

agonnen wrote:
Sat Aug 31, 2019 6:49 pm
Related:
https://hackaday.com/2019/08/31/micropy ... er-better/
Thanks, c2ffi is quite hard to follow accross clang versionning your alternative looks promising !



Related but for direct C++ integration this time

https://github.com/pmp-p/panda3d-interrogator

Despite the name closely related to Panda3D python game engine, it also provide the ground for a general purpose tool called "interrogate" to convert *ANY* C++ library instantly to a pure micropython module + a C lib loaded at runtime given your ffi support is working ( unix port , and maybe some wasm port).

Post Reply