Overte C++ Documentation
HelperScriptEngine.h
1 //
2 // HelperScriptEngine.h
3 // libraries/script-engine/src/HelperScriptEngine.h
4 //
5 // Created by dr Karol Suprynowicz on 2024/04/28.
6 // Copyright 2024 Overte e.V.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef overte_HelperScriptEngine_h
13 #define overte_HelperScriptEngine_h
14 
15 #include <mutex>
16 #include "QThread"
17 
18 #include "ScriptEngine.h"
19 
32 public:
35 
36  template <typename F>
37  inline void run(F&& f) {
38  std::lock_guard<std::mutex> guard(_scriptEngineLock);
39  f();
40  }
41 
42  template <typename T, typename F>
43  inline T runWithResult(F&& f) {
44  T result;
45  {
46  std::lock_guard<std::mutex> guard(_scriptEngineLock);
47  result = f();
48  }
49  return result;
50  }
51 
57  ScriptEngine* get() { return _scriptEngine.get(); };
58  ScriptEnginePointer getShared() { return _scriptEngine; };
59 private:
60  std::mutex _scriptEngineLock;
61  ScriptEnginePointer _scriptEngine { nullptr };
62  std::shared_ptr<QThread> _scriptEngineThread { nullptr };
63 };
64 
65 #endif //overte_HelperScriptEngine_h
Provides a wrapper around script engine that does not have ScriptManager.
Definition: HelperScriptEngine.h:31
ScriptEngine * get()
Returns pointer to the script engine.
Definition: HelperScriptEngine.h:57
Provides an engine-independent interface for a scripting engine.
Definition: ScriptEngine.h:93