[fpc-pascal] Python interaction... how?

2018-02-15 Thread Darius Blaszyk
Hi all,

I just cannot wrap my head around this one. I would like to implement scripting 
support to a pure FPC application. The application implements some modifier on 
an internal data structure which will be exposed to python as a module. The 
data structure itself is managed by the calling application. How to do this?

Something like:
- FPC app has integer variable a=1
- FPC app calls python script
- Python script adds 10 to a eg pymod.increase_counter(10)
- FPC app variable a is now 11

Does anyone know of a minimal example or pseudo code or just an explanation?

Rgds. Darius
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Python interaction... how?

2018-02-16 Thread leledumbo via fpc-pascal
> Does anyone know of a minimal example or pseudo code or just an
explanation?

Python actually provides a Python.h that you can convert to a Pascal unit.
But inside, it includes a bunch of other header files and conversion might
be a tedious task. If you made it, though, simply call:

Py_Initialize();
Py_WhateverThereAreMultipleChoicesHere(ProbablyAPythonScriptAsCString);
Py_Finalize();

and you're done.

But if I have to, I would take the external program approach instead using
its interpreter's -c option through TProcess. Communication will then be
done through pipes. It's probably slower, but quicker to work. If you take
the header conversion approach, however, that might benefit everyone else
needing to do the same, just like how the Lua bindings are done (but they're
a lot cleaner that makes conversion simpler).



--
Sent from: http://free-pascal-general.1045716.n5.nabble.com/
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Python interaction... how?

2018-02-16 Thread Michael Van Canneyt



On Fri, 16 Feb 2018, leledumbo via fpc-pascal wrote:


Does anyone know of a minimal example or pseudo code or just an

explanation?

Python actually provides a Python.h that you can convert to a Pascal unit.
But inside, it includes a bunch of other header files and conversion might
be a tedious task. If you made it, though, simply call:

Py_Initialize();
Py_WhateverThereAreMultipleChoicesHere(ProbablyAPythonScriptAsCString);
Py_Finalize();

and you're done.


This task has been done for you. See:

http://wiki.freepascal.org/Python4Delphi

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Python interaction... how?

2018-02-17 Thread Darius Blaszyk
Thanks for the tips and hints! I found this page also explaining well on
how to embed python bi-directionally in FPC.
https://docs.python.org/3.4/extending/embedding.html

The P4D code was very helpful as well. I stripped all the object and
component code and now have a working FPC only python binding for Python
3.6. I'm still cleaning up the code and testing the demo apps from the
python site, but if someone is interested I can post a link here.

Darius


Virus-free.
www.avg.com

<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Fri, Feb 16, 2018 at 9:59 AM, Michael Van Canneyt  wrote:

>
>
> On Fri, 16 Feb 2018, leledumbo via fpc-pascal wrote:
>
> Does anyone know of a minimal example or pseudo code or just an
>>>
>> explanation?
>>
>> Python actually provides a Python.h that you can convert to a Pascal unit.
>> But inside, it includes a bunch of other header files and conversion might
>> be a tedious task. If you made it, though, simply call:
>>
>> Py_Initialize();
>> Py_WhateverThereAreMultipleChoicesHere(ProbablyAPythonScriptAsCString);
>> Py_Finalize();
>>
>> and you're done.
>>
>
> This task has been done for you. See:
>
> http://wiki.freepascal.org/Python4Delphi
>
> Michael.
>
> ___
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Python interaction... how?

2018-02-18 Thread Michael Van Canneyt



On Sat, 17 Feb 2018, Darius Blaszyk wrote:


Thanks for the tips and hints! I found this page also explaining well on
how to embed python bi-directionally in FPC.
https://docs.python.org/3.4/extending/embedding.html

The P4D code was very helpful as well. I stripped all the object and
component code and now have a working FPC only python binding for Python
3.6. I'm still cleaning up the code and testing the demo apps from the
python site, but if someone is interested I can post a link here.


Maybe put it in the FPC wiki page that I referred to, so it will not get
lost ?

http://wiki.freepascal.org/Python4Delphi

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal