Browse Source

make sure boost filesystem is type casted consistlty

python
Jørgen Lien Sellæg 7 years ago committed by Jørgen Sverre Lien Sellæg
parent
commit
b898db575f
  1. 1
      src/debug_lldb.cpp
  2. 19
      src/plugins.h
  3. 21
      src/python_type_casters.h
  4. 1
      tests/python_interpreter_test.cc
  5. 2
      tests/python_interpreter_test_files/terminal_test.py

1
src/debug_lldb.cpp

@ -10,6 +10,7 @@
#include "utility.hpp"
#include <boost/filesystem.hpp>
#include <iostream>
#include <pybind11/stl.h>
extern char **environ;

19
src/plugins.h

@ -1,26 +1,7 @@
#pragma once
#include "python_interpreter.h"
#include <boost/filesystem.hpp>
#include <pybind11/embed.h>
namespace pybind11 {
namespace detail {
template <>
struct type_caster<boost::filesystem::path> {
public:
PYBIND11_TYPE_CASTER(boost::filesystem::path, _("str"));
bool load(handle src, bool) {
value = std::string(pybind11::str(src));
return !PyErr_Occurred();
}
static handle cast(boost::filesystem::path src, return_value_policy, handle) {
return pybind11::str(src.string());
}
};
} // namespace detail
} // namespace pybind11
class __attribute__((visibility("default")))
Plugins {
public:

21
src/python_type_casters.h

@ -0,0 +1,21 @@
#pragma once
#include "python_bind.h"
#include <boost/filesystem.hpp>
namespace pybind11 {
namespace detail {
template <>
struct type_caster<boost::filesystem::path> {
public:
PYBIND11_TYPE_CASTER(boost::filesystem::path, _("str"));
bool load(handle src, bool) {
value = std::string(pybind11::str(src));
return !PyErr_Occurred();
}
static handle cast(boost::filesystem::path src, return_value_policy, handle) {
return pybind11::str(src.string());
}
};
} // namespace detail
} // namespace pybind11

1
tests/python_interpreter_test.cc

@ -3,6 +3,7 @@
#include "python_interpreter.h"
#include "terminal.h"
#include "config.h"
#include "python_type_casters.h"
class __attribute__((visibility("default")))

2
tests/python_interpreter_test_files/terminal_test.py

@ -1,6 +1,6 @@
from Jucipp import Terminal
t = Terminal();
t = Terminal()
def hello_world():
t.print("Hello, World!\n")

Loading…
Cancel
Save