NAP
pythonscriptservice.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 #include <utility/dllexport.h>
8 #include <pybind11/pybind11.h>
9 #include <pybind11/stl.h>
10 #include <pybind11/embed.h>
11 #include "nap/service.h"
12 
13 namespace nap
14 {
18  class NAPAPI PythonScriptService : public Service
19  {
20  RTTI_ENABLE(Service)
21 
22  public:
24 
29  void registerObjectCreators(rtti::Factory& factory) override;
30 
38  bool TryLoad(const std::string& modulePath, pybind11::module& module, utility::ErrorState& errorState);
39 
40  private:
41  using ModuleMap = std::unordered_map<std::string, pybind11::module>;
42  using SystemPathSet = std::unordered_set<std::string>;
43 
44  pybind11::scoped_interpreter mInterpreter; // Note: must be first member to ensure it's destroyed last. Otherwise module destruction will crash.
45  ModuleMap mLoadedModules;
46  SystemPathSet mSystemPaths;
47 
48  };
49 }
nap::utility::ErrorState
Definition: errorstate.h:19
nap::ServiceConfiguration
Definition: service.h:28
nap::Service
Definition: templateservice.h:8
nap::rtti::Factory
Definition: factory.h:78
nap
Definition: templateapp.h:17
nap::PythonScriptService
Definition: pythonscriptservice.h:18