plugify  1.0.0.0
language_module.hpp
1 #pragma once
2 
3 #include <array>
4 #include <cstring>
5 #include <memory>
6 #include <plugify/mem_addr.hpp>
7 #include <string>
8 #include <variant>
9 #include <vector>
10 
11 namespace plugify {
12  class PluginRef;
13  class ModuleRef;
14  class MethodRef;
15  class IPlugifyProvider;
16 
24  using MethodData = std::pair<MethodRef, MemAddr>;
25 
32  struct ErrorData {
33  //string error; ///< Description of the error.
34 
35  std::array<char, 255> error{};
36 
37  ErrorData(std::string_view str) {
38  std::memcpy(error.data(), str.data(), std::min(str.length(), error.size() - 1));
39  }
40  };
41 
48  struct InitResultData {};
49 
56  struct LoadResultData {
57  std::vector<MethodData> methods;
58  };
59 
66  using InitResult = std::variant<InitResultData, ErrorData>;
67 
74  using LoadResult = std::variant<LoadResultData, ErrorData>;
75 
83  protected:
84  ~ILanguageModule() = default;
85 
86  public:
93  virtual InitResult Initialize(std::weak_ptr<IPlugifyProvider> provider, ModuleRef module) = 0;
94 
98  virtual void Shutdown() = 0;
99 
105  virtual LoadResult OnPluginLoad(PluginRef plugin) = 0;
106 
111  virtual void OnPluginStart(PluginRef plugin) = 0;
112 
117  virtual void OnPluginEnd(PluginRef plugin) = 0;
118 
123  virtual void OnMethodExport(PluginRef plugin) = 0;
124 
131  //virtual void OnGameFrame() = 0;
132 
137  virtual bool IsDebugBuild() = 0;
138  };
139 } // namespace plugify
Interface for user-implemented language modules.
virtual bool IsDebugBuild()=0
Handle actions to be performed on each game frame.
virtual InitResult Initialize(std::weak_ptr< IPlugifyProvider > provider, ModuleRef module)=0
Initialize the language module.
virtual void OnPluginEnd(PluginRef plugin)=0
Handle plugin end event.
virtual void Shutdown()=0
Shutdown the language module.
virtual void OnMethodExport(PluginRef plugin)=0
Handle method export event.
virtual LoadResult OnPluginLoad(PluginRef plugin)=0
Handle plugin load event.
virtual void OnPluginStart(PluginRef plugin)=0
Handle plugin start event.
Reference wrapper to access language module's information.
Definition: module.hpp:37
Reference wrapper to access for plugin's information.
Definition: plugin.hpp:52
Holds information about an error.
std::array< char, 255 > error
Description of the error.
Holds information about the initialization result.
Holds information about the load result.
std::vector< MethodData > methods
Methods exported by the loaded plugin.