* Where to find good/simple examples for gnatcoll (python)?
@ 2016-10-18 17:48 reinkor
2016-10-19 8:15 ` Vratislav Podzimek
0 siblings, 1 reply; 6+ messages in thread
From: reinkor @ 2016-10-18 17:48 UTC (permalink / raw)
Hi,
I try to learn fast to use gnatcoll (especially to access python functions).
I would therefore like to have simple examples where an ada program calls
a python script calculating for example 2 + 3 and return 5 (to ada).
Did not directly find this in the documentation included in gnatcoll debian packages.
Somebody any hint?
reinert
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Where to find good/simple examples for gnatcoll (python)?
2016-10-18 17:48 Where to find good/simple examples for gnatcoll (python)? reinkor
@ 2016-10-19 8:15 ` Vratislav Podzimek
2016-10-19 12:01 ` reinkor
0 siblings, 1 reply; 6+ messages in thread
From: Vratislav Podzimek @ 2016-10-19 8:15 UTC (permalink / raw)
On Tue, 18 Oct 2016 10:48:17 -0700, reinkor wrote:
> Hi,
>
> I try to learn fast to use gnatcoll (especially to access python
> functions).
> I would therefore like to have simple examples where an ada program
> calls a python script calculating for example 2 + 3 and return 5 (to
> ada).
> Did not directly find this in the documentation included in gnatcoll
> debian packages.
>
> Somebody any hint?
>
> reinert
Maybe http://www.adacore.com/adaanswers/gems/gem-106-lady-ada-kisses-
python-part-2/ could be helpful?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Where to find good/simple examples for gnatcoll (python)?
2016-10-19 8:15 ` Vratislav Podzimek
@ 2016-10-19 12:01 ` reinkor
2016-10-20 7:57 ` briot.emmanuel
0 siblings, 1 reply; 6+ messages in thread
From: reinkor @ 2016-10-19 12:01 UTC (permalink / raw)
Thanks so far, but as I understand, the example here is about the opposite: to access Ada from Python.
reinert
onsdag 19. oktober 2016 10.15.21 UTC+2 skrev Vratislav Podzimek følgende:
> On Tue, 18 Oct 2016 10:48:17 -0700, reinkor wrote:
>
> > Hi,
> >
> > I try to learn fast to use gnatcoll (especially to access python
> > functions).
> > I would therefore like to have simple examples where an ada program
> > calls a python script calculating for example 2 + 3 and return 5 (to
> > ada).
> > Did not directly find this in the documentation included in gnatcoll
> > debian packages.
> >
> > Somebody any hint?
> >
> > reinert
>
> Maybe http://www.adacore.com/adaanswers/gems/gem-106-lady-ada-kisses-
> python-part-2/ could be helpful?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Where to find good/simple examples for gnatcoll (python)?
2016-10-19 12:01 ` reinkor
@ 2016-10-20 7:57 ` briot.emmanuel
2016-10-21 8:27 ` reinkor
0 siblings, 1 reply; 6+ messages in thread
From: briot.emmanuel @ 2016-10-20 7:57 UTC (permalink / raw)
If you only want to execute a python script (and perhaps get the output as a
string), you could try:
Python : constant Scripting_Language :=
Lookup_Scripting_Language (Repo, "python");
GNATCOLL.Scripts.Execute_Command (Python, "2 + 3");
Now, if you want to get the result, this is a little more complicated. Assuming you
want to call a foo() function in python, you have to prepare an object with the arguments,
and that will receive the return value.
Data : Callback_Data'Class := Create (Python, 0);
Result : Integer;
Data.Execute_Expression ("2+3"); -- newer versions of gnatcoll
Result := Data.Return_Value;
or
Data : Callback_Data'Class := Create (Python, 2);
Result : Integer;
Data.Set_Nth_Arg (1, 2);
Data.Set_Nth_Arg (2, 3);
Data.Execute_Command ("foo"); -- newer versions of gnatcoll
Result := Data.Return_Value;
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Where to find good/simple examples for gnatcoll (python)?
2016-10-20 7:57 ` briot.emmanuel
@ 2016-10-21 8:27 ` reinkor
2016-10-31 8:40 ` briot.emmanuel
0 siblings, 1 reply; 6+ messages in thread
From: reinkor @ 2016-10-21 8:27 UTC (permalink / raw)
Thanks so far.
My up to date debian jessie seems not yet to include these new features.
However, I tried the program below. It builds, but I get
"raised CONSTRAINT_ERROR : t1.adb:10 access check failed"
(something goes wring at the line
"Data : Callback_Data'Class := Create (Python, 2);")
Any help in my attempt to learn fast is appreciated.
with Ada.Text_IO; use Ada.Text_IO;
with GNATCOLL.Scripts; use GNATCOLL.Scripts;
with GNATCOLL.Scripts.Python; use GNATCOLL.Scripts.Python;
with GNATCOLL.Scripts.Shell; use GNATCOLL.Scripts.Shell;
procedure T1 is
Repo : Scripts_Repository := new Scripts_Repository_Record;
Python : Scripting_Language := Lookup_Scripting_Language (Repo, "python");
Data : Callback_Data'Class := Create (Python, 2);
Result : Integer;
begin
Data.Set_Nth_Arg (1, 2);
Data.Set_Nth_Arg (2, 3);
Data.Execute_Command ("./test1.py"); -- newer versions of gnatcoll
Result := Data.Return_Value;
end T1;
Here is the project file for it:
with "gnatcoll_python";
with "gnatcoll_gmp";
project T1 is
for Source_Dirs use ("src");
for Object_Dir use "obj";
for Exec_Dir use ".";
for Main use ("t1.adb");
end T1;
reinert
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Where to find good/simple examples for gnatcoll (python)?
2016-10-21 8:27 ` reinkor
@ 2016-10-31 8:40 ` briot.emmanuel
0 siblings, 0 replies; 6+ messages in thread
From: briot.emmanuel @ 2016-10-31 8:40 UTC (permalink / raw)
> "raised CONSTRAINT_ERROR : t1.adb:10 access check failed"
This error message tells you quite precisely that the variable Python is null.
And from there we can deduce that ou never registered python as a scripting
language.
You need to call GNATCOLL.Scripts.Python.Register_Python_Scripting.
Check the "Loading the scripting language" section in the GNATCOLL
documentation
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2016-10-31 8:40 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-18 17:48 Where to find good/simple examples for gnatcoll (python)? reinkor
2016-10-19 8:15 ` Vratislav Podzimek
2016-10-19 12:01 ` reinkor
2016-10-20 7:57 ` briot.emmanuel
2016-10-21 8:27 ` reinkor
2016-10-31 8:40 ` briot.emmanuel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox