How to embed python ?
Sebastian Andersson
sa at hogia.net
Mon Sep 9 05:24:27 EDT 2002
I've got an old game server where I would like to make the server
extensible via python code which will be called when things happen in
the game. I would like to call different code depening on the event
and I would like to pass on different data.
In the game server I've got level files where I intend to put the
python code. It will look something like this:
triggers {
0,0 79,17 (enter) {
def my_helper_function():
rch2.message(m, NOW, "Hello there")
my_helper_function()
rch2.message(m, NOW, " and bye now!)
};
};
(The first two lines and the last two lines are part of the level file
format).
I use Py_CompileString to compile the python code. As it is now I have
to remove the extra white space before each line while building the
string. Is there a way around that to let Py_CompileString do it by
itself? Or even better, is there a way to pass each line by itself
to the python parser and let it signal when the white space count
has become too small (ie on the " };" line) ?
How should I organize the python code?
The first argument to all "triggers" is an integer called m.
Then follows one, two or three arguments that vary depending on
the trigger.
Should I make each piece of code into a function with the correct
arguments or should I just put the triggers' arguments into variables
before calling the code with PyImport_ExecCodeModule ?
Should I use the code as above or should I put it inside a function
definition and later call that function instead of using
PyImport_ExecCodeModule ?
I want each trigger call to be as fast as possible.
TIA,
/Sebastian
More information about the Python-list
mailing list