aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-06-19 22:04:33 (GMT)
committerPavel Labath <pavelo@centrum.sk>2011-11-01 09:57:19 (GMT)
commitd4ff16c0e739663a0fec8b471d83e7004189fb29 (patch)
tree16d995f800c08d9ee370d0189c65343520f0c0c6 /src
parent1661bb6d848e8f52cfe10a13704853fd4209eeee (diff)
downloadfluxbox_paul-d4ff16c0e739663a0fec8b471d83e7004189fb29.zip
fluxbox_paul-d4ff16c0e739663a0fec8b471d83e7004189fb29.tar.bz2
Fix saving of resources.
Diffstat (limited to 'src')
-rw-r--r--src/FbTk/LResourceHelper.lua95
1 files changed, 66 insertions, 29 deletions
diff --git a/src/FbTk/LResourceHelper.lua b/src/FbTk/LResourceHelper.lua
index e2899f8..5171c43 100644
--- a/src/FbTk/LResourceHelper.lua
+++ b/src/FbTk/LResourceHelper.lua
@@ -22,7 +22,9 @@ local function newindex(table, key, value)
22 local meta = getmetatable(table); 22 local meta = getmetatable(table);
23 local t, mt = check_arg(table, key); 23 local t, mt = check_arg(table, key);
24 24
25 if type(value) == 'table' then 25 if mt == res_magic then
26 write_resource(t, value);
27 elseif type(value) == 'table' then
26 if mt == res_magic then 28 if mt == res_magic then
27 myerror(table, '"' .. key .. '" is a resource.'); 29 myerror(table, '"' .. key .. '" is a resource.');
28 end; 30 end;
@@ -35,8 +37,6 @@ local function newindex(table, key, value)
35 else 37 else
36 if mt ~= nil and mt._magic == cat_magic and mt._state == 1 then 38 if mt ~= nil and mt._magic == cat_magic and mt._state == 1 then
37 myerror(table, '"' .. key .. '" is a category.'); 39 myerror(table, '"' .. key .. '" is a category.');
38 elseif mt == res_magic then
39 write_resource(t, value);
40 else 40 else
41 meta[key] = value; 41 meta[key] = value;
42 end; 42 end;
@@ -101,39 +101,76 @@ local function register_resource(root, name, object)
101 return register_resource(t, tail, object); 101 return register_resource(t, tail, object);
102end; 102end;
103 103
104local function dump_(key, value, fd) 104function value_to_string(key, value)
105 if type(value) == 'table' then 105 if type(value) == 'string' then
106 fd:write(key, ' = {}\n'); 106 return string.format('%q', value);
107 for k, v in pairs(value) do 107 elseif type(value) == 'number' then
108 k = append_name(key, k); 108 return string.format('%g', value);
109 109 elseif type(value) == 'boolean' then
110 local mt = getmetatable(v); 110 if value then
111 if mt ~= nil and mt._magic == cat_magic then 111 return "true";
112 v = mt; 112 else
113 elseif mt == res_magic then 113 return "false";
114 v = read_resource(v); 114 end;
115 else
116 error('Unsupported value type for ' .. key .. ': ' .. type(value));
117 end;
118end;
119
120local function dump_res(key, value, fd)
121 local first = true;
122 for k, v in pairs(value) do
123 if append_name(key, k) ~= nil then
124 if first ~= true then
125 fd:write(',');
115 end; 126 end;
127 fd:write(' ');
128 first = false;
116 129
117 if k ~= nil then 130 if type(k) == 'string' then
118 dump_(k, v, fd); 131 fd:write(k, ' = ');
132 end;
133
134 if type(v) == 'table' then
135 fd:write('{');
136 dump_res(k, v, fd);
137 fd:write('} ');
138 else
139 fd:write(value_to_string(k, v));
119 end; 140 end;
120 end; 141 end;
121 fd:write('\n'); 142 end;
122 else 143 if first ~= true then
123 if type(value) == 'string' then 144 fd:write(' ');
124 value = string.format('%q', value); 145 end;
125 elseif type(value) == 'number' then 146end;
126 value = string.format('%g', value); 147
127 elseif type(value) == 'boolean' then 148local function dump_(key, value, fd)
128 if value then 149 for k, v in pairs(value) do
129 value = "true"; 150 k = append_name(key, k);
151
152 local mt = getmetatable(v);
153 if mt ~= nil and mt._magic == cat_magic then
154 v = mt;
155 elseif mt == res_magic then
156 v = read_resource(v);
157 end;
158
159 if k ~= nil then
160 if type(v) == 'table' then
161 fd:write(k, ' = {');
162 if mt == res_magic then
163 dump_res(k, v, fd);
164 fd:write('}\n');
165 else
166 fd:write('}\n');
167 dump_(k, v, fd);
168 fd:write('\n');
169 end;
130 else 170 else
131 value = "false"; 171 fd:write(k, ' = ', value_to_string(k, v), '\n');
132 end; 172 end;
133 else
134 error('Unsupported value type for ' .. key .. ': ' .. type(value));
135 end; 173 end;
136 fd:write(key, ' = ', value, '\n');
137 end; 174 end;
138end; 175end;
139 176