NicTheQuick hat geschrieben: 05.05.2025 14:25
...um den Python-Teil zu kompilieren und mit Purebasic zu mischen?
Das klingt sehr komplex.
Hallo Nic,
vielleicht ist das nicht so komplex. Auf der Webseite steht:
Cython gives you the combined power of Python and C to let you
write Python code that calls back and forth from and to C or C++ code natively at any point.
easily tune readable Python code into plain C performance by adding static type declarations, also in Python syntax."
Integrate natively with existing code and data from legacy, low-level or high-performance libraries and applications.
Und ebenfalls,vielleicht besonders wichtig:
All of this makes Cython the ideal language for wrapping external C libraries, embedding CPython into existing applications, and for fast C modules that speed up the execution of Python code.
In der Cython Wiki steht zum Kompilieren folgendes:
Cython code must, unlike Python, be compiled. This happens in two stages:
A .pyx or .py file is compiled by Cython to a .c file, containing the code of a Python extension module.
The .c file is compiled by a C compiler to a .so file (or .pyd on Windows) which can be import-ed directly into a Python session.
setuptools takes care of this part. Although Cython can call them for you in certain cases.
There are several ways to build Cython code:
Run the cythonize command-line utility. This is a good approach for compiling a single Cython source file directly to an extension. A source file can be built “in place” (so that the extension module is created next to the source file, ready to be imported) with cythonize -i filename.pyx.
or
Run the cython command-line utility manually to produce the .c file from the .pyx file, then manually compiling the .c file into a shared object library or DLL suitable for import from Python. (These manual steps are mostly for debugging and experimentation.) "
Ich habe mal die beiden Kommandozeilen Varianten rausgesucht.
Wenn man nun einmal überlegt, entweder Fred oder mit einem Tool würde man den Pythoncode per Kommandozeile übergeben und mit dem C-Code von PB kombinieren. Das sollte eigentlich möglich sein, und man könnte es mit Kommandozeilen-Aufrufen erledigen.Wahrscheinlich gibt es auch elegantere Wege.
Der umgekehrte Weg geht natürlich auch: In Cython den C-Code erzeugen und in den PB-C-Code integrieren, wenn man selber frickeln will.
Ich sehe auch keinen Vorteil für solche Sachen PureBasic zu nutzen. Diese Welt ist viel zu schnelllebig und ich bin sicher niemand würde freiwillig irgendwelche PureBasic-Bindings dafür warten wollen. Ein ambitioniertes Projekt wäre es aber allemal.
Unter Umständen muss man dann nicht viel Wartung betreiben. Vielleicht würde in PB ja so etwas wie beim C-Code ( !) oder ein Befehl wie
BEGINPython und ENDPython eingefügt. Und der Vorteil dürfte klar sein: die große Befehlsvielfalt von PB mit der Power von Python-Modulen,
die so in PB nicht zu finden sind, da gibt es ja einige.
Ich bin leider nicht ein erfahrener Programmierer, schreibe nur gelegentlich ein kurzes Programm.
Du hast nicht zufällig Lust, mal ein kleines Experiment beim Kombinieren von PB-C-Code und Py-Code mit Cython zu starten ?
