1 |
1 |
2 local _G = _G; |
2 local _G = _G; |
3 local setmetatable, loadfile, pcall, rawget, rawset, io = |
3 local setmetatable, loadfile, pcall, rawget, rawset, io = |
4 setmetatable, loadfile, pcall, rawget, rawset, io; |
4 setmetatable, loadfile, pcall, rawget, rawset, io; |
|
5 |
5 module "configmanager" |
6 module "configmanager" |
6 |
7 |
7 local parsers = {}; |
8 local parsers = {}; |
8 |
9 |
9 local config = { ["*"] = { core = {} } }; |
10 local config = { ["*"] = { core = {} } }; |
50 return false; |
51 return false; |
51 end |
52 end |
52 |
53 |
53 function load(filename, format) |
54 function load(filename, format) |
54 format = format or filename:match("%w+$"); |
55 format = format or filename:match("%w+$"); |
|
56 |
55 if parsers[format] and parsers[format].load then |
57 if parsers[format] and parsers[format].load then |
56 local f = io.open(filename); |
58 local f, err = io.open(filename); |
57 if f then |
59 if f then |
58 local ok, err = parsers[format].load(f:read("*a")); |
60 local ok, err = parsers[format].load(f:read("*a")); |
59 f:close(); |
61 f:close(); |
60 return ok, err; |
62 return ok, err; |
61 end |
63 end |
|
64 return f, err; |
62 end |
65 end |
|
66 |
63 if not format then |
67 if not format then |
64 return nil, "no parser specified"; |
68 return nil, "no parser specified"; |
65 else |
69 else |
66 return false, "no parser"; |
70 return nil, "no parser for "..(format); |
67 end |
71 end |
68 end |
72 end |
69 |
73 |
70 function save(filename, format) |
74 function save(filename, format) |
71 end |
75 end |