Skip to content

Commit 2899a69

Browse files
committed
fix: guards for template specialization of pyobject fromJson()
1 parent 38fb950 commit 2899a69

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ target_link_libraries(${BTCPP_LIBRARY}
192192
if(BTCPP_PYTHON)
193193
find_package(Python COMPONENTS Interpreter Development)
194194
find_package(pybind11 CONFIG)
195+
message("PYTHON_EXECUTABLE: ${Python_EXECUTABLE}")
195196

196197
pybind11_add_module(btpy_cpp src/python/bindings.cpp)
197198
target_compile_options(btpy_cpp PRIVATE -Wno-gnu-zero-variadic-macro-arguments)

include/behaviortree_cpp/json_export.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22

33
#include "behaviortree_cpp/utils/safe_any.hpp"
44
#include "behaviortree_cpp/basic_types.h"
5-
65
// Use the version nlohmann::json embedded in BT.CPP
76
#include "behaviortree_cpp/contrib/json.hpp"
87

8+
#ifdef BTCPP_PYTHON
9+
#include <pybind11/pybind11.h>
10+
#include <pybind11/pytypes.h>
11+
#include "behaviortree_cpp/contrib/pybind11_json.hpp"
12+
#endif
13+
914
namespace BT
1015
{
1116

@@ -88,7 +93,6 @@ class JsonExporter
8893
dst = *fromJson<T>(src);
8994
}
9095

91-
9296
/**
9397
* @brief Register new JSON converters with addConverter<Foo>().
9498
* You should used first the macro BT_JSON_CONVERTER.
@@ -126,7 +130,14 @@ class JsonExporter
126130
std::unordered_map<std::type_index, FromJonConverter> from_json_array_converters_;
127131
std::unordered_map<std::string, BT::TypeInfo> type_names_;
128132
};
129-
133+
#ifdef BTCPP_PYTHON
134+
template <>
135+
inline Expected<pybind11::object>
136+
JsonExporter::fromJson(const nlohmann::json& source) const
137+
{
138+
return pyjson::from_json(source);
139+
}
140+
#endif
130141
template <typename T>
131142
inline Expected<T> JsonExporter::fromJson(const nlohmann::json& source) const
132143
{

python_examples/ex01_sample.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
Demo adapted from [btcpp_sample](https://github.com/BehaviorTree/btcpp_sample).
55
"""
66

7+
import sys
8+
sys.path.append('/home/shaurk/git/moveit_pro/dependencies/BehaviorTree.CPP/build')
79
from btpy import BehaviorTreeFactory, SyncActionNode, NodeStatus, ports
810

911

0 commit comments

Comments
 (0)