Otclient  14/8/2020
main.cpp
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 
26 #include <client/client.h>
27 
28 int main(int argc, const char* argv[])
29 {
30  std::vector<std::string> args(argv, argv + argc);
31 
32  // setup application name and version
33  g_app.setName("OTClient");
34  g_app.setCompactName("otclient");
35  g_app.setVersion(VERSION);
36 
37  // initialize application framework and otclient
38  g_app.init(args);
39  g_client.init(args);
40 
41  // find script init.lua and run it
42  if(!g_resources.discoverWorkDir("init.lua"))
43  g_logger.fatal("Unable to find work directory, the application cannot be initialized.");
44 
45  if(!g_lua.safeRunScript("init.lua"))
46  g_logger.fatal("Unable to run script init.lua!");
47 
48  // the run application main loop
49  g_app.run();
50 
51  // unload modules
52  g_app.deinit();
53 
54  // terminate everything and free memory
56  g_app.terminate();
57  return 0;
58 }
Application::terminate
virtual void terminate()
Definition: application.cpp:124
resourcemanager.h
luainterface.h
Application::setVersion
void setVersion(const std::string &version)
Definition: application.h:46
Logger::fatal
void fatal(const std::string &what)
Definition: logger.h:55
Application::deinit
virtual void deinit()
Definition: application.cpp:104
g_resources
ResourceManager g_resources
Definition: resourcemanager.cpp:32
LuaInterface::safeRunScript
bool safeRunScript(const std::string &fileName)
Loads and runs a script, any errors are printed to stdout and returns false.
Definition: luainterface.cpp:301
Application::setCompactName
void setCompactName(const std::string &compactName)
Definition: application.h:45
g_logger
Logger g_logger
Definition: logger.cpp:35
g_lua
LuaInterface g_lua
Definition: luainterface.cpp:31
ConsoleApplication::run
void run()
Definition: consoleapplication.cpp:34
g_client
Client g_client
Definition: client.cpp:34
g_app
ConsoleApplication g_app
Definition: consoleapplication.cpp:32
main
int main(int argc, const char *argv[])
Definition: main.cpp:28
Application::init
virtual void init(std::vector< std::string > &args)
Definition: application.cpp:64
Application::setName
void setName(const std::string &name)
Definition: application.h:44
ResourceManager::discoverWorkDir
bool discoverWorkDir(const std::string &existentFile)
Definition: resourcemanager.cpp:45
client.h
Client::terminate
void terminate()
Definition: client.cpp:84
Client::init
void init(std::vector< std::string > &args)
Definition: client.cpp:36
application.h