Need calling python from C
Chris Gonnerman
chris.gonnerman at newcenturycomputers.net
Tue Sep 18 23:34:44 EDT 2001
----- Original Message -----
From: "Jay" <jryansourceforge at yahoo.com>
> I have tried a few things without luck.
>
> I am trying to enable readline.bind_key(key,function)
>
> to be called from python and execute the GNU readline
> library module that python comes with.
>
> I am editing readline.c in order to make this
> feasible.
>
> Here is my problem...
>
> I need to gain access to a pointer to a python
> function while I am in C.
Wrong angle, I'm afraid. There is no such thing. You need to
store the PyObject (don't forget the PY_INCREF) and then pass
a pointer to a wrapper function in C to rl_bind_key(). The
wrapper will call the Python function when it is itself called.
For a good example, go to
http://newcenturycomputers.net/projects/readline.html
and download the source for my Alternative Readline. I carefully
extracted (hacked and cut) some code from /F's windows console
module; it's called _rlsetup.c in the source distro for
Alternative Readline. You could just look at /F's console
module source, but mine is a bit smaller and the _rlsetup.c
file is simplified.
More information about the Python-list
mailing list