4 ms·
You can interface with existing libraries if you really want, you need to somehow expose a C ABI (be it via the library written in C, exposing an official C ABI
by badsectoracula 2y ago
You can interface with existing libraries if you really want, you need to somehow expose a C ABI (be it via the library written in C, exposing an official C ABI or you writing a C bridge).
There is a 3rd party "Python-for-Lazarus" bridge[0] though for simple stuff you can use the python library directly:
program foo;
{$MODE OBJFPC}
uses CTypes;
const PyLib = 'python3.11';
procedure Py_Initialize; cdecl; external PyLib;
function PyRun_SimpleString(Command: PChar): CInt; cdecl; external PyLib;
begin
Py_Initialize;
PyRun_SimpleString(
'from tkinter import *'#13 +
'window = Tk()'#13 +
'window.title("Hello, world!")'#13 +
'button = Button(window, text="Clicky")'#13 +
'button.grid()'#13 +
'window.mainloop()');
end.
The above uses the Tk library that comes with Python.
Also depending on what you want to do chances are there is already a Free Pascal library or existing bindings to a library written in another language. If not, if the library has a C header file you can use the h2pas utility that comes with FPC to make your own (though the generated code does need some modifications to work more often than not).
Of course all the above do assume you have knowledge of both Free Pascal and whatever you want to interface with, but at least as far as being able to access existing libraries is concerned, it should be possible - just with some hoops (and at that point it depends on how much you value whatever Lazarus provides over the effort involved in whatever library you want to use).
EDIT: and truth be told IMO the biggest roadblock with Lazarus isn't so much the language but that it is just not easy to learn most of that stuff (the core language and runtime library is decently documented but anything outside of that can be a hit and miss) and you basically need an almost arrogant attitude of "this is just dumb code, not magic, if it is technically possible i can figure out myself how to do it" :-P.
[0] https://github.com/Alexey-T/Python-for-Lazarus https://github.com/Alexey-T/Python-for-Lazarus