ScriptManager.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Script/LuaBinder.h>
  7. namespace anki
  8. {
  9. // Forward
  10. class SceneGraph;
  11. class MainRenderer;
  12. /// @addtogroup script
  13. /// @{
  14. /// The scripting manager.
  15. class ScriptManager
  16. {
  17. public:
  18. ScriptManager();
  19. ~ScriptManager();
  20. /// Create the script manager.
  21. ANKI_USE_RESULT Error init(AllocAlignedCallback allocCb, void* allocCbData);
  22. void setRenderer(MainRenderer* renderer)
  23. {
  24. m_otherSystems.m_renderer = renderer;
  25. }
  26. void setSceneGraph(SceneGraph* scene)
  27. {
  28. m_otherSystems.m_sceneGraph = scene;
  29. }
  30. LuaBinderOtherSystems& getOtherSystems()
  31. {
  32. return m_otherSystems;
  33. }
  34. /// Expose a variable to the scripting engine.
  35. template<typename T>
  36. void exposeVariable(const char* name, T* y)
  37. {
  38. LockGuard<Mutex> lock(n_luaMtx);
  39. LuaBinder::exposeVariable<T>(m_lua.getLuaState(), name, y);
  40. }
  41. /// Evaluate a string
  42. ANKI_USE_RESULT Error evalString(const CString& str)
  43. {
  44. LockGuard<Mutex> lock(n_luaMtx);
  45. return LuaBinder::evalString(m_lua.getLuaState(), str);
  46. }
  47. ANKI_INTERNAL LuaBinder& getLuaBinder()
  48. {
  49. return m_lua;
  50. }
  51. ANKI_INTERNAL ScriptAllocator getAllocator() const
  52. {
  53. return m_alloc;
  54. }
  55. private:
  56. LuaBinderOtherSystems m_otherSystems;
  57. ScriptAllocator m_alloc;
  58. LuaBinder m_lua;
  59. Mutex n_luaMtx;
  60. };
  61. /// @}
  62. } // end namespace anki