a lot of changes in modules

This commit is contained in:
Eduardo Bart
2012-02-06 17:19:47 -02:00
parent add8505a5b
commit 88301c329a
50 changed files with 488 additions and 322 deletions

View File

@@ -3,6 +3,8 @@ Module
description: Contains core lua classes, functions and constants used by other modules
author: OTClient team
website: https://github.com/edubart/otclient
autoload: true
autoload-antecedence: 10
onLoad: |
dofile 'ext/table'
@@ -21,5 +23,3 @@ Module
dofile 'keyboard'
dofile 'mouse'
onUnload: |
rootWidget = nil

View File

@@ -1,34 +1,20 @@
local eventId = 0
local eventList = {}
function scheduleEvent(func, delay)
if not func then return end
eventId = eventId + 1
local id = eventId
local function proxyFunc()
if eventList[id] then
if eventList[id].active then
func()
end
eventList[id] = nil
end
end
eventList[id] = { func = proxyFunc, active = true }
if delay and delay > 0 then
g_dispatcher.scheduleEvent(proxyFunc, delay)
else
g_dispatcher.addEvent(proxyFunc, false)
end
return id
local event = g_dispatcher.scheduleEvent(callback, delay)
-- must hold a reference to the callback, otherwise it would be collected
event._callback = callback
return event
end
function addEvent(func)
return scheduleEvent(func, 0)
function addEvent(callback, front)
local event = g_dispatcher.addEvent(callback, front)
-- must hold a reference to the callback, otherwise it would be collected
event._callback = callback
return event
end
function removeEvent(id)
if id and eventList[id] then
eventList[id].active = false
return true
function removeEvent(event)
if event then
event:cancel()
end
end

View File

@@ -74,3 +74,16 @@ function createWidget(style, parent)
widget:setStyle(style)
return widget
end
function reloadModule(name)
local module = g_modules.getModule(name)
if module then
module:reload()
end
end
function reloadModules()
g_modules.reloadModules()
end

View File

@@ -35,6 +35,28 @@ function connect(object, signalsAndSlots, pushFront)
end
end
function disconnect(object, signalsAndSlots)
for signal,slot in pairs(signalsAndSlots) do
if not object[signal] then
elseif type(object[signal]) == 'function' then
if object[signal] == slot then
object[signal] = nil
end
elseif type(object[signal]) == 'table' then
for k,func in pairs(object[signal]) do
if func == slot then
table.remove(object[signal], k)
if #object[signal] == 1 then
object[signal] = object[signal][1]
end
break
end
end
end
end
end
function extends(base)
local derived = {}
function derived.internalCreate()