12 local t_insert = table.insert; |
12 local t_insert = table.insert; |
13 local t_concat = table.concat; |
13 local t_concat = table.concat; |
14 local error = error; |
14 local error = error; |
15 local pairs = pairs; |
15 local pairs = pairs; |
16 |
16 |
|
17 local debug_traceback = debug.traceback; |
|
18 local log = require "util.logger".init("serialization"); |
17 module "serialization" |
19 module "serialization" |
18 |
20 |
19 local indent = function(i) |
21 local indent = function(i) |
20 return string_rep("\t", i); |
22 return string_rep("\t", i); |
21 end |
23 end |
48 func(t, indent(ind-1)); |
50 func(t, indent(ind-1)); |
49 func(t, "}"); |
51 func(t, "}"); |
50 elseif type(o) == "boolean" then |
52 elseif type(o) == "boolean" then |
51 func(t, (o and "true" or "false")); |
53 func(t, (o and "true" or "false")); |
52 else |
54 else |
53 error("cannot serialize a " .. type(o)) |
55 log("warn", "cannot serialize a %s: %s", type(o), debug_traceback()) |
54 end |
56 end |
55 end |
57 end |
56 |
58 |
57 function append(t, o) |
59 function append(t, o) |
58 _simplesave(o, 1, t, t.write or t_insert); |
60 _simplesave(o, 1, t, t.write or t_insert); |