mirror of
https://github.com/edubart/otclient.git
synced 2025-11-30 07:26:49 +01:00
handle close event in lua
This commit is contained in:
@@ -10,6 +10,14 @@ function fatal(msg)
|
||||
Logger.log(LogFatal, msg)
|
||||
end
|
||||
|
||||
function setonclose(func)
|
||||
g_app.onClose = func
|
||||
end
|
||||
|
||||
function exit()
|
||||
g_app.exit()
|
||||
end
|
||||
|
||||
function connect(object, signalsAndSlots, pushFront)
|
||||
for signal,slot in pairs(signalsAndSlots) do
|
||||
if not object[signal] then
|
||||
|
||||
@@ -60,5 +60,15 @@ function Game.onDeath()
|
||||
print('dead')
|
||||
end
|
||||
|
||||
local function onApplicationClose()
|
||||
print('close app')
|
||||
if Game.isOnline() then
|
||||
Game.logout(false)
|
||||
else
|
||||
exit()
|
||||
end
|
||||
end
|
||||
|
||||
setonclose(onApplicationClose)
|
||||
connect(Game, { onLogin = Game.createInterface }, true)
|
||||
connect(Game, { onLogout = Game.destroyInterface })
|
||||
|
||||
Reference in New Issue
Block a user