|
Revision 316, 0.5 kB
(checked in by slact, 7 months ago)
|
|
no more segfaults on load. no more leaks loading or dumping. added info table. dumping still a bit sketchy for high nesting levels
|
-
Property svn:eol-style set to
native
-
Property svn:keywords set to
Author Date Id Revision
|
| Line | |
|---|
| 1 | -- borrow from lposix |
|---|
| 2 | -- |
|---|
| 3 | require "syck" |
|---|
| 4 | |
|---|
| 5 | yaml = {} |
|---|
| 6 | |
|---|
| 7 | function yaml.dump(obj, io) |
|---|
| 8 | if io then |
|---|
| 9 | io:write(syck.dump(obj)) |
|---|
| 10 | else |
|---|
| 11 | return syck.dump(obj) |
|---|
| 12 | end |
|---|
| 13 | end |
|---|
| 14 | |
|---|
| 15 | function yaml.dump_file(obj, file) |
|---|
| 16 | local f, err = io.open(file, "w") |
|---|
| 17 | if not f then return nil, err end |
|---|
| 18 | f:write(yaml.dump(obj)) |
|---|
| 19 | f:close() |
|---|
| 20 | end |
|---|
| 21 | |
|---|
| 22 | function yaml.load(str) |
|---|
| 23 | return syck.load(str) |
|---|
| 24 | end |
|---|
| 25 | |
|---|
| 26 | function yaml.load_file(file) |
|---|
| 27 | local f, err = io.open(file, "r") |
|---|
| 28 | if not f then return nil, err end |
|---|
| 29 | local ret = yaml.load(f:read("*all")) |
|---|
| 30 | f:close() |
|---|
| 31 | return ret |
|---|
| 32 | end |
|---|
| 33 | |
|---|
| 34 | setmetatable(yaml, {__index=syck}) |
|---|