Skip to content
Snippets Groups Projects
Commit c08dafc3 authored by Nicolas Mansard's avatar Nicolas Mansard Committed by Nicolas Mansard
Browse files

Merge branch 'topic/jrl-mal' of github.com:jrl-umi3218/dynamic-graph-python into topic/jrl-mal

parents e7fe252b 08187020
No related branches found
No related tags found
No related merge requests found
......@@ -50,6 +50,9 @@ namespace dynamicgraph {
/// \param stream input stream
std::string processStream(std::istream& stream, std::ostream& os);
/// \brief Return a pointer to the dictionary of global variables
PyObject* globals();
private:
/// Pointer to the dictionary of global variables
PyObject* globals_;
......
......@@ -18,7 +18,9 @@
#
INCLUDE(FindPythonLibs)
IF (NOT ${PYTHONLIBS_FOUND} STREQUAL TRUE)
MESSAGE(FATAL_ERROR "Python has not been found.")
MESSAGE(FATAL_ERROR "Python has not been found.")
ELSE()
MESSAGE(STATUS "PYTHON_LIBRARY=${PYTHON_LIBRARY}")
ENDIF (NOT ${PYTHONLIBS_FOUND} STREQUAL TRUE)
INCLUDE(FindPythonInterp)
......@@ -83,7 +85,9 @@ SET_TARGET_PROPERTIES(${PYTHON_MODULE}
TARGET_LINK_LIBRARIES(${PYTHON_MODULE} ${DYNAMIC_GRAPH_LIBRARIES})
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
CONFIG_FILES(link-to-python.hh)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH}
${CMAKE_CURRENT_BINARY_DIR})
#
# Installation
......
......@@ -16,6 +16,7 @@
#include <iostream>
#include "dynamic-graph/python/interpreter.hh"
#include "link-to-python.hh"
// Python initialization commands
namespace dynamicgraph {
......@@ -31,9 +32,13 @@ namespace dynamicgraph {
}
using dynamicgraph::python::Interpreter;
using dynamicgraph::python::libpython;
Interpreter::Interpreter()
{
// load python dynamic library
// this is silly, but required to be able to import dl module.
dlopen(libpython.c_str(), RTLD_LAZY | RTLD_GLOBAL);
Py_Initialize();
mainmod_ = PyImport_AddModule("__main__");
Py_INCREF(mainmod_);
......@@ -98,6 +103,11 @@ std::string Interpreter::python( const std::string& command )
return value;
}
PyObject* Interpreter::globals()
{
return globals_;
}
void Interpreter::runPythonFile( std::string filename )
{
PyObject* pymainContext = globals_;
......
// -*- mode: c++ -*-
// Copyright 2011, Florent Lamiraux, CNRS.
//
// This file is part of dynamic-graph-python.
// dynamic-graph is free software: you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// dynamic-graph is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
#ifdef WIN32
#include <Windows.h>
#else
#include <dlfcn.h>
#endif
namespace dynamicgraph {
namespace python {
std::string libpython("@PYTHON_LIBRARY@");
} // namespace python
} // namespace dynamicgraph
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment