ScriptManager.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. // Forward
  9. class SceneGraph;
  10. class MainRenderer;
  11. /// @addtogroup script
  12. /// @{
  13. /// The scripting manager.
  14. class ScriptManager
  15. {
  16. public:
  17. ScriptManager();
  18. ~ScriptManager();
  19. /// Create the script manager.
  20. ANKI_USE_RESULT Error init(AllocAlignedCallback allocCb, void* allocCbData);
  21. void setRenderer(MainRenderer* renderer)
  22. {
  23. m_otherSystems.m_renderer = renderer;
  24. }
  25. void setSceneGraph(SceneGraph* scene)
  26. {
  27. m_otherSystems.m_sceneGraph = scene;
  28. }
  29. LuaBinderOtherSystems& getOtherSystems()
  30. {
  31. return m_otherSystems;
  32. }
  33. /// Expose a variable to the scripting engine.
  34. template<typename T>
  35. void exposeVariable(const char* name, T* y)
  36. {
  37. LockGuard<Mutex> lock(n_luaMtx);
  38. LuaBinder::exposeVariable<T>(m_lua.getLuaState(), name, y);
  39. }
  40. /// Evaluate a string
  41. ANKI_USE_RESULT Error evalString(const CString& str)
  42. {
  43. LockGuard<Mutex> lock(n_luaMtx);
  44. return LuaBinder::evalString(m_lua.getLuaState(), str);
  45. }
  46. ANKI_INTERNAL LuaBinder& getLuaBinder()
  47. {
  48. return m_lua;
  49. }
  50. ANKI_INTERNAL ScriptAllocator getAllocator() const
  51. {
  52. return m_alloc;
  53. }
  54. private:
  55. LuaBinderOtherSystems m_otherSystems;
  56. ScriptAllocator m_alloc;
  57. LuaBinder m_lua;
  58. Mutex n_luaMtx;
  59. };
  60. /// @}
  61. } // end namespace anki