ScriptEnvironment.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright (C) 2009-present, 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. /// @addtogroup script
  9. /// @{
  10. /// A sandboxed LUA environment.
  11. class ScriptEnvironment
  12. {
  13. public:
  14. /// Expose a variable to the scripting engine.
  15. template<typename T>
  16. void exposeVariable(const char* name, T* y)
  17. {
  18. LuaBinder::exposeVariable<T>(m_thread.getLuaState(), name, y);
  19. }
  20. /// Evaluate a string
  21. Error evalString(const CString& str)
  22. {
  23. return LuaBinder::evalString(m_thread.getLuaState(), str);
  24. }
  25. void serializeGlobals(LuaBinderSerializeGlobalsCallback& callback)
  26. {
  27. LuaBinder::serializeGlobals(m_thread.getLuaState(), callback);
  28. }
  29. void deserializeGlobals(const void* data, PtrSize dataSize)
  30. {
  31. LuaBinder::deserializeGlobals(m_thread.getLuaState(), data, dataSize);
  32. }
  33. lua_State& getLuaState()
  34. {
  35. return *m_thread.getLuaState();
  36. }
  37. private:
  38. LuaBinder m_thread;
  39. };
  40. /// @}
  41. } // end namespace anki