Better implementation for forming the singleton wrapper.

This commit is contained in:
BenDol 2014-04-01 17:08:07 +13:00
parent 79ee0e34ea
commit 994f49b3c1
2 changed files with 26 additions and 49 deletions

View File

@ -1,82 +1,47 @@
-- @docclass local config = g_configs.getSettings()
g_settings = {
impl = g_configs.getSettings()
}
function g_settings.save() g_settings = makesingleton(config)
g_settings.impl:save()
end
function g_settings.setList(key, list)
g_settings.impl:setList(key, list)
end
function g_settings.getList(key)
g_settings.impl:getList(key)
end
function g_settings.exists(key)
g_settings.impl:exists(key)
end
function g_settings.remove(key)
g_settings.impl:remove(key)
end
function g_settings.setNode(key, node)
g_settings.impl:setNode(key, node)
end
function g_settings.getNode(key)
g_settings.impl:getNode(key)
end
function g_settings.mergeNode(key, node)
g_settings.impl:mergeNode(key, node)
end
-- convenience methods
function g_settings.set(key, value) function g_settings.set(key, value)
g_settings.impl:set(key, value) config:set(key, value)
end end
function g_settings.setDefault(key, value) function g_settings.setDefault(key, value)
return g_settings.impl:setDefault(key, value) return config:setDefault(key, value)
end end
function g_settings.get(key, default) function g_settings.get(key, default)
return g_settings.impl:get(key, default) return config:get(key, default)
end end
function g_settings.getString(key, default) function g_settings.getString(key, default)
return g_settings.impl:getString(key, default) return config:getString(key, default)
end end
function g_settings.getInteger(key, default) function g_settings.getInteger(key, default)
return g_settings.impl:getInteger(key, default) return config:getInteger(key, default)
end end
function g_settings.getNumber(key, default) function g_settings.getNumber(key, default)
return g_settings.impl:getNumber(key, default) return config:getNumber(key, default)
end end
function g_settings.getBoolean(key, default) function g_settings.getBoolean(key, default)
return g_settings.impl:getBoolean(key, default) return config:getBoolean(key, default)
end end
function g_settings.getPoint(key, default) function g_settings.getPoint(key, default)
return g_settings.impl:getPoint(key, default) return config:getPoint(key, default)
end end
function g_settings.getRect(key, default) function g_settings.getRect(key, default)
return g_settings.impl:getRect(key, default) return config:getRect(key, default)
end end
function g_settings.getSize(key, default) function g_settings.getSize(key, default)
return g_settings.impl:getSize(key, default) return config:getSize(key, default)
end end
function g_settings.getColor(key, default) function g_settings.getColor(key, default)
return g_settings.impl:getColor(key, default) return config:getColor(key, default)
end end

View File

@ -332,4 +332,16 @@ function getOppositeAnchor(anchor)
return anchor return anchor
end end
function makesingleton(obj)
local singleton = {}
if obj.getClassName then
for key,value in pairs(_G[obj:getClassName()]) do
if type(value) == 'function' then
singleton[key] = function(...) value(obj, ...) end
end
end
end
return singleton
end
-- @} -- @}