8 #include <pybind11/pybind11.h>
9 #include <pybind11/stl.h>
12 #include <rtti/rtti.h>
13 #include <nap/signalslot.h>
14 #include <componentptr.h>
15 #include <nap/logger.h>
16 #include <instanceproperty.h>
17 #include <rtti/object.h>
18 #include <nap/resourceptr.h>
19 #include <entityptr.h>
20 #include <pythonscriptservice.h>
21 #include <pythonscript.h>
28 class PythonScriptComponent;
29 class PythonScriptComponentInstance;
48 bool init(utility::ErrorState& errorState) override;
51 std::
string mClassName;
52 std::vector<std::
string> mDependencies;
55 virtual
void getDependentComponents(std::vector<rtti::
TypeInfo>& components) const override;
58 pybind11::module mModule;
59 pybind11::
object mPythonClass;
79 virtual void update(
double deltaTime)
override;
92 template <
typename ReturnType,
typename ...Args>
93 bool get(
const std::string& identifier,
utility::ErrorState& errorState, ReturnType& returnValue, Args&&... args);
104 template <
typename ...Args>
109 pybind11::object mInstance;
110 bool mInitialized =
false;
118 template <
typename ReturnType,
typename ...Args>
123 returnValue = mInstance.attr(identifier.c_str())(args...).template cast<ReturnType>();
125 catch (
const pybind11::error_already_set& err)
127 errorState.
fail(
"Runtime python error while executing %s: %s", mResource->mPythonScript->mPath.c_str(), err.what());
134 template <
typename ...Args>
139 mInstance.attr(identifier.c_str())(std::forward<Args>(args)...);
141 catch (
const pybind11::error_already_set& err)
143 errorState.
fail(
"Runtime python error while executing %s: %s", mResource->mPythonScript->mPath.c_str(), err.what());