dynamic-graph-py.cc 976 Bytes
Newer Older
florent's avatar
florent committed
1
2
3
4
5
6
7
/*
 *  Copyright 2010 (C) CNRS
 *  Author: Florent Lamiraux
 */

#include <Python.h>
#include <iostream>
florent's avatar
florent committed
8
#include <sstream>
florent's avatar
florent committed
9
10
#include <string>

florent's avatar
florent committed
11
#include <dynamic-graph/interpreter.h>
florent's avatar
florent committed
12

florent's avatar
florent committed
13
static dynamicgraph::Interpreter interpreter;
florent's avatar
florent committed
14
15
16
17
18
19
20
21
22

static PyObject*
plug(PyObject* self, PyObject* args)
{
  char* out = NULL;
  char* in = NULL;
  if (!PyArg_ParseTuple(args,"ss", &out, &in))
    return NULL;

florent's avatar
florent committed
23
24
25
26
27
28
  std::stringstream ss;
  std::ostringstream os;
  ss << std::string(out) << " " << std::string(in);
  std::istringstream cmdArg(ss.str());
  interpreter.cmdPlug(std::string("plug"), cmdArg, os);

florent's avatar
florent committed
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
  return Py_BuildValue("");
}

/**
   \brief List of python functions
*/
static PyMethodDef sotTutorialMethods[] = {
  {"plug",  plug, METH_VARARGS,
     "plug an output signal into an input signal"},
  {NULL, NULL, 0, NULL}        /* Sentinel */
};

PyMODINIT_FUNC
initwrap(void)
{
    PyObject *m;

    m = Py_InitModule("wrap", sotTutorialMethods);
    if (m == NULL)
        return;
}