![]() |
От: |
Marty
|
https://www.youtube.com/channel/UChp5PpQ6T4-93HbNF-8vSYg |
Дата: | 03.10.09 15:18 | ||
Оценка: |
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
#include <boost/python.hpp>
char const* greet()
{
return "hello, world";
}
BOOST_PYTHON_MODULE(hello_ext)
{
using namespace boost::python;
def("greet", greet);
}
import hello_ext
printf hello.greet()
ni module named hello_ext
#ifdef _DEBUG
#undef _DEBUG
#endif
#include <Python.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
static PyObject *SpamError;
static PyObject *
spam_system(PyObject *self, PyObject *args)
{
const char *command;
int sts;
if (!PyArg_ParseTuple(args, "s", &command))
return NULL;
sts = system(command);
return Py_BuildValue("i", sts);
}
static PyMethodDef SpamMethods[] = {
//...
{"system", spam_system, METH_VARARGS,
"Execute a shell command."},
//...
{NULL, NULL, 0, NULL} /* Sentinel */
};
PyMODINIT_FUNC
initspam(void)
{
PyObject *m;
m = Py_InitModule("spam", SpamMethods);
if (m == NULL)
return;
SpamError = PyErr_NewException("spam.error", NULL, NULL);
Py_INCREF(SpamError);
PyModule_AddObject(m, "error", SpamError);
}