@@ -35,9 +35,12 @@ class ConfigHandler
3535 @userConfig = {}
3636 @config = setmetatable {} , {
3737 __index : ( _, k) ->
38- if @userConfig [ k] ~= nil return @userConfig [ k]
38+ if @userConfig and @userConfig [ k] ~= nil
39+ return @userConfig [ k]
3940 else return @defaults [ k]
40- __newindex : ( _, k, v) -> @userConfig [ k] = v
41+ __newindex : ( _, k, v) ->
42+ @userConfig or= {}
43+ @userConfig [ k] = v
4144 }
4245 @c = @config -- shortcut
4346
@@ -57,6 +60,7 @@ class ConfigHandler
5760 parent = tbl. __parent
5861
5962 -- deep copy whole defaults entry (without copying attached metatables)
63+ @userConfig or= {}
6064 @userConfig [ tbl. __key] = util. deep_copy @defaults [ tbl. __key]
6165 -- set specific property originally requested on copy
6266 tbl = @userConfig [ tbl. __key]
@@ -122,24 +126,36 @@ class ConfigHandler
122126 break
123127 else return false , errors. badKey\ format " retrive" , i, tostring ( @section [ i] ) , type config
124128
129+ @userConfig or= {}
125130 @userConfig [ k] = v for k, v in pairs config
126131 return sectionExists
127132
128133 mergeSection : ( config) =>
129- section = config
134+ section, sectionExists = config, true
130135 -- create missing parent sections
131136 for i= 1 , # @section
132137 childSection = section[ @section [ i]]
133138 if childSection == nil
139+ -- don't create parent sections if this section is going to be deleted
140+ unless @userConfig
141+ sectionExists = false
142+ break
134143 section[ @section [ i]] = {}
135144 childSection = section[ @section [ i]]
136145 elseif " table" != type childSection
137146 return false , errors. badKey\ format " update" , i, tostring ( @section [ i] ) , type childSection
138- section = childSection
147+ section = childSection if @userConfig or i < # @section
139148 -- merge our values into our section
140- section[ k] = v for k, v in pairs @userConfig
149+ if @userConfig
150+ section[ k] = v for k, v in pairs @userConfig
151+ elseif sectionExists
152+ section[ @section [ # @section ]] = nil
141153 return config
142154
155+ delete : ( concertWrite, waitLockTime) =>
156+ @userConfig = nil
157+ return @write concertWrite, waitLockTime
158+
143159 write : ( concertWrite, waitLockTime = 5000 ) =>
144160 return false , errors. noFile unless @file
145161
@@ -228,6 +244,7 @@ class ConfigHandler
228244
229245 import : ( tbl = {} , keys) =>
230246 changesMade = false
247+ @userConfig or= {}
231248 keys = { key, true for key in * keys} if keys
232249
233250 for k, v in pairs tbl
0 commit comments