I need information about extending and embedding Python
Fredrik Lundh
fredrik at pythonware.com
Tue Dec 14 06:38:11 EST 1999
Cesar Lopez <clopez at abo.fi> wrote:
> I need to make a library for python to update some external devices in
> an embeded system with a little Hitachi microcontroller, so I need
> information about How to do that, I must to define a method to define
> librarys to control devices like, RS-232 port, Leds, Keyboards,
> Speakers.
>
> Now I´ve defined a litle program in C++, its control a green Led
> (on/off) and now I want to do that with the python interpreter, so I
> need your help.
here's an example (in plain old C):
---
#include "Python.h"
static PyObject *
device_set(PyObject* self, PyObject* args)
{
int status;
int value;
if (!PyArg_ParseTuple(args, "i", &value))
return NULL;
/* do something! */
status = whatever(value);
return Py_BuildValue("i", status);
}
static PyMethodDef _functions[] = {
{"set", device_set, 1},
{NULL, NULL}
};
void
#ifdef WIN32
__declspec(dllexport)
#endif
initdevice()
{
Py_InitModule("device", _functions);
}
---
import device
device.set(1) # switch it on!
---
for more info, see:
"Extending and Embedding the Python Interpreter"
http://www.python.org/doc/current/ext/ext.html
"Python/C API Reference Manual"
http://www.python.org/doc/current/api/api.html
and all the existing modules in the standard
library...
</F>
More information about the Python-list
mailing list