Mailing List Archive

Embedding Question from a Newbie
This is a multi-part message in MIME format.

------=_NextPart_000_00B5_01BEB41C.2B697C90
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

i have a question. i am new to python and am trying to use it as a =
scripting language for a game i am working on. I have the interpreter =
embedded and running scripts but i have a few questions.

1) can i return values from the python script to the C/C++ program?
for example say at the end of my script, it returned 'character' and =
character was equal to say 'hi'
now is there anyway my C/C++ program could find out that the script just =
returned the value 'hi'?

2) is there anyway I can pass values from the C/C++ program into the =
python script?

and

3) say i had a python script that had several functions (defs). is there =
anyway i could call just one of these defs from the C/C++ program =
without calling the entire script?

Thanks for your help

------=_NextPart_000_00B5_01BEB41C.2B697C90
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2516.1900" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>i have a question. i am new to python =
and am trying=20
to use it as a scripting language for a game i am working on. I have the =

interpreter embedded and running scripts but i have a few=20
questions.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>1) can i return values from the python =
script to=20
the C/C++ program?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>for example say at the end of my =
script, it=20
returned 'character' and character was equal to say 'hi'</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>now is there anyway my C/C++ program =
could find out=20
that the script just returned the value 'hi'?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>2) is there anyway I can pass values =
from the C/C++=20
program into the python script?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>and</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>3) say&nbsp;i had a python script that =
had several=20
functions (defs). is there anyway i could call just one of these defs =
from the=20
C/C++ program without calling the entire script?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks for your =
help</FONT></DIV></BODY></HTML>

------=_NextPart_000_00B5_01BEB41C.2B697C90--
Embedding Question from a Newbie [ In reply to ]
CyRiuS writes:
> i have a question. i am new to python and am trying to use it as a
> scripting language for a game i am working on. I have the
> interpreter embedded and running scripts but i have a few questions.
>
> 1) can i return values from the python script to the C/C++ program?
> for example say at the end of my script, it returned 'character' and
> character was equal to say 'hi' now is there anyway my C/C++ program
> could find out that the script just returned the value 'hi'?
>
> 2) is there anyway I can pass values from the C/C++ program into the
> python script?
>
> and
>
> 3) say i had a python script that had several functions (defs). is
> there anyway i could call just one of these defs from the C/C++
> program without calling the entire script?

The answer to all 3 is yes. The details will be found in the
embedding docs and the C API docs. I'd guess so far you've only used
the Very High Level layer (PyRun_ etc). You want to start exploring
the Abstract layer, where you work with PySequences and such. At that
level it's still pretty straight forward. Drop down further only if
you really have to. Almost anything you'll need to do is done
somewhere in the Modules or Objects subdirectories.

grep-is-your-best-friend-ly y'rs

- Gordon