handle close event in lua

This commit is contained in:
Eduardo Bart
2012-01-07 03:35:50 -02:00
parent 806fb5995f
commit a3721b3a11
9 changed files with 34 additions and 12 deletions

View File

@@ -212,6 +212,15 @@ void Application::poll()
g_dispatcher.poll();
}
void Application::close()
{
g_lua.getGlobalField("g_app", "onClose");
if(!g_lua.isNil())
g_lua.protectedCall();
else
exit();
}
void Application::render()
{
// everything is rendered by UI components

View File

@@ -41,7 +41,7 @@ public:
virtual void run();
virtual void exit();
virtual void poll();
virtual void close() { exit(); }
virtual void close();
void setPollCycleDelay(int delay) { m_pollCycleDelay = delay; }

View File

@@ -234,6 +234,10 @@ void Application::registerLuaFunctions()
// Protocol
g_lua.registerClass<Protocol>();
// Application
g_lua.registerStaticClass("g_app");
g_lua.bindClassStaticFunction("g_app", "exit", std::bind(&Application::exit, g_app));
// ConfigManager
g_lua.registerStaticClass("g_configs");
g_lua.bindClassStaticFunction("g_configs", "set", std::bind(&ConfigManager::set, &g_configs, _1, _2));
@@ -241,7 +245,7 @@ void Application::registerLuaFunctions()
g_lua.bindClassStaticFunction("g_configs", "exists", std::bind(&ConfigManager::exists, &g_configs, _1));
g_lua.bindClassStaticFunction("g_configs", "remove", std::bind(&ConfigManager::remove, &g_configs, _1));
// PlatformWindow
g_lua.registerStaticClass("g_window");
g_lua.bindClassStaticFunction("g_window", "move", std::bind(&PlatformWindow::move, &g_window, _1));
g_lua.bindClassStaticFunction("g_window", "resize", std::bind(&PlatformWindow::resize, &g_window, _1));

View File

@@ -54,7 +54,6 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassStaticFunction("g_sprites", "isLoaded", std::bind(&SpriteManager::isLoaded, &g_sprites));
g_lua.bindClassStaticFunction("g_sprites", "getSignature", std::bind(&SpriteManager::getSignature, &g_sprites));
g_lua.bindGlobalFunction("exit", std::bind(&Application::exit, g_app));
g_lua.bindGlobalFunction("getOufitColor", Outfit::getColor);
g_lua.registerClass<ProtocolLogin, Protocol>();

View File

@@ -39,10 +39,3 @@ void OTClient::init(const std::vector<std::string>& args)
g_modules.ensureModuleLoaded("client");
g_modules.autoLoadModules(1000);
}
void OTClient::close()
{
if(g_game.isOnline())
g_game.logout(true);
exit();
}

View File

@@ -31,7 +31,6 @@ class OTClient : public Application
public:
OTClient();
void init(const std::vector<std::string>& args);
void close();
void registerLuaFunctions();
};