Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
LuaBinding.hpp
1 // Copyright (C) 2017 Jérôme Leclercq
2 // This file is part of the "Nazara Development Kit"
3 // For conditions of distribution and use, see copyright notice in Prerequesites.hpp
4 
5 #pragma once
6 
7 #ifndef NDK_LUABINDING_HPP
8 #define NDK_LUABINDING_HPP
9 
10 #include <NDK/Entity.hpp>
11 #include <NDK/Lua/LuaBinding_Base.hpp>
12 #include <memory>
13 
14 namespace Ndk
15 {
16  class NDK_API LuaBinding
17  {
18  friend class LuaBinding_SDK;
19 
20  public:
21  LuaBinding();
22  ~LuaBinding() = default;
23 
24  template<typename T> void BindComponent(const Nz::String& name);
25 
26  void RegisterClasses(Nz::LuaState& state);
27 
28  std::unique_ptr<LuaBinding_Base> core;
29  std::unique_ptr<LuaBinding_Base> math;
30  std::unique_ptr<LuaBinding_Base> network;
31  std::unique_ptr<LuaBinding_Base> sdk;
32  std::unique_ptr<LuaBinding_Base> utility;
33 
34  #ifndef NDK_SERVER
35  std::unique_ptr<LuaBinding_Base> audio;
36  std::unique_ptr<LuaBinding_Base> graphics;
37  std::unique_ptr<LuaBinding_Base> renderer;
38  std::unique_ptr<LuaBinding_Base> platform;
39  #endif
40 
41  private:
42  template<typename T>
43  static int AddComponentOfType(Nz::LuaState& lua, EntityHandle& handle);
44 
45  template<typename T>
46  static int PushComponentOfType(Nz::LuaState& lua, BaseComponent& component);
47 
48  using AddComponentFunc = int(*)(Nz::LuaState&, EntityHandle&);
49  using GetComponentFunc = int(*)(Nz::LuaState&, BaseComponent&);
50 
51  struct ComponentBinding
52  {
53  AddComponentFunc adder;
54  ComponentIndex index;
55  GetComponentFunc getter;
56  Nz::String name;
57  };
58 
59  ComponentBinding* QueryComponentIndex(Nz::LuaState& lua, int argIndex = 2);
60 
61  std::vector<ComponentBinding> m_componentBinding;
62  std::unordered_map<Nz::String, ComponentIndex> m_componentBindingByName;
63  };
64 }
65 
66 #include <NDK/Lua/LuaBinding.inl>
67 
68 #endif // NDK_LUABINDING_HPP
TODO: For now is unable to display different color in the history, it needs a RichTextDrawer to do so...
Definition: Algorithm.hpp:12
Core class that represents a string.
Definition: String.hpp:22
NDK class that represents the binding between the engine & the SDK with the Lua scripting.
Definition: LuaBinding.hpp:16
NDK class that represents the common base of all components.
Definition: BaseComponent.hpp:17