[Tutor] Embedding Python
Mon, 20 Mar 2000 13:17:23 -0500
Greetings, after reading the standard extending/embedding
documents, questions are still plagueing me. Please, could
Here is my situation:
A small sized c++ class wrapping basic (n)curses functions. Here
is a quick view of the header file(if you feel the source file is needed
also, please let me know):
int myROWS; //max number of rows(lines) on screen
int myCOLS; //max number of columns on screen
int dispTop; //top boundary
int dispBottom; //bottom boundary
int dispLeft; //left boundary
int dispRight; //right boundary
bool hasColours; //not used, yet
int getChar(); //used to get keyboard input
void update(); //update, or refresh the screen
void clearDisplay(); //clears only the display window
void moveChar(int row, int col, char c); //moves cursor to row x
col and prints c
void placeCursor(int row, int col); //position cursor at row x col
void movePlayer(int key, int row, int col, me *); //used to move
player, check for boundaries, etc.
bool checkBoundary(int row, int col); //upon movement, will
player collide with boundary(ies)?
void addMessage(string); //insert a message into message bar
This has already been tested with a small c++ program, to verify it
works. Simply, it allows me to specific a 'window' on screen in
which the player (specified by a character) can move. When a
boundary is encountered, a message is printed on screen (via
addMessage) telling the player what boundary was 'touched'. Still
Now, I want to learn to embed Python in this small program. The
purpose is varied: use Python to control the player, create
instances of class screen, etc. Finally, my questions:
From the docs, it seems I have to create wrapper
classes/functions for my class screen. Is this true?
Can I rather change the class so it can accept direct python
objects(etc) without use of a wrapper function?
If a wrapper is necessary, can I make the wrapper as a c++ class,
or must it be standard functions?
If it seems I am totally off-base with these questions ("Did he
actually read the docs? Or is he jsut saying he did?") Please point
out my errors. Also, are there good, simple examples of Python
embedded in a c++ program. Especially a small program with
source I can study.