Otclient  14/8/2020
module.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 OTClient <https://github.com/edubart/otclient>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
23 #ifndef MODULE_H
24 #define MODULE_H
25 
26 #include "declarations.h"
27 
30 
31 // @bindclass
32 class Module : public LuaObject
33 {
34 public:
35  Module(const std::string& name);
36 
37  bool load();
38  void unload();
39  bool reload();
40 
41  bool canUnload() { return m_loaded && m_reloadable && !isDependent(); }
42  bool canReload() { return m_reloadable && !isDependent(); }
43  bool isLoaded() { return m_loaded; }
44  bool isReloadable() { return m_reloadable; }
45  bool isDependent();
46  bool isSandboxed() { return m_sandboxed; }
47  bool hasDependency(const std::string& name, bool recursive = false);
48  int getSandbox(LuaInterface *lua);
49 
50  std::string getDescription() { return m_description; }
51  std::string getName() { return m_name; }
52  std::string getAuthor() { return m_author; }
53  std::string getWebsite() { return m_website; }
54  std::string getVersion() { return m_version; }
55  bool isAutoLoad() { return m_autoLoad; }
56  int getAutoLoadPriority() { return m_autoLoadPriority; }
57 
58  // @dontbind
59  ModulePtr asModule() { return static_self_cast<Module>(); }
60 
61 protected:
62  void discover(const OTMLNodePtr& moduleNode);
63  friend class ModuleManager;
64 
65 private:
66  stdext::boolean<false> m_loaded;
67  stdext::boolean<false> m_autoLoad;
68  stdext::boolean<false> m_reloadable;
69  stdext::boolean<false> m_sandboxed;
70  int m_autoLoadPriority;
71  int m_sandboxEnv;
72  std::tuple<std::string, std::string> m_onLoadFunc;
73  std::tuple<std::string, std::string> m_onUnloadFunc;
74  std::string m_name;
75  std::string m_description;
76  std::string m_author;
77  std::string m_website;
78  std::string m_version;
79  std::function<void()> m_loadCallback;
80  std::function<void()> m_unloadCallback;
81  std::list<std::string> m_dependencies;
82  std::list<std::string> m_scripts;
83  std::list<std::string> m_loadLaterModules;
84 };
85 
86 #endif
Module::asModule
ModulePtr asModule()
Definition: module.h:59
Module::unload
void unload()
Definition: module.cpp:113
Module::getDescription
std::string getDescription()
Definition: module.h:50
Module::load
bool load()
Definition: module.cpp:36
declarations.h
Module::getWebsite
std::string getWebsite()
Definition: module.h:53
stdext::boolean< false >
luaobject.h
Module::canUnload
bool canUnload()
Definition: module.h:41
ModuleManager
Definition: modulemanager.h:29
Module::hasDependency
bool hasDependency(const std::string &name, bool recursive=false)
Definition: module.cpp:167
declarations.h
Module::isLoaded
bool isLoaded()
Definition: module.h:43
Module::getAuthor
std::string getAuthor()
Definition: module.h:52
Module::getSandbox
int getSandbox(LuaInterface *lua)
Definition: module.cpp:183
LuaInterface
Class that manages LUA stuff.
Definition: luainterface.h:32
Module
Definition: module.h:32
Module::isSandboxed
bool isSandboxed()
Definition: module.h:46
stdext::shared_object_ptr
Definition: shared_object.h:39
Module::getAutoLoadPriority
int getAutoLoadPriority()
Definition: module.h:56
Module::getName
std::string getName()
Definition: module.h:51
Module::canReload
bool canReload()
Definition: module.h:42
Module::isAutoLoad
bool isAutoLoad()
Definition: module.h:55
LuaObject
LuaObject, all script-able classes have it as base.
Definition: luaobject.h:30
Module::isDependent
bool isDependent()
Definition: module.cpp:158
Module::discover
void discover(const OTMLNodePtr &moduleNode)
Definition: module.cpp:189
Module::isReloadable
bool isReloadable()
Definition: module.h:44
Module::Module
Module(const std::string &name)
Definition: module.cpp:30
Module::getVersion
std::string getVersion()
Definition: module.h:54
Module::reload
bool reload()
Definition: module.cpp:152