-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyaml.lua
47 lines (39 loc) · 1004 Bytes
/
yaml.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
local lyaml = require 'lyaml'
local io = io
local coroutine = coroutine
local print = print
package.loaded[...] = {}
module(...)
load = lyaml.load
dump = lyaml.dump
local function file_loader(file)
local yaml_str = ""
while(true) do
local line = file:read("*l")
if (line == "---" and yaml_str) then
local r = lyaml.load(yaml_str)
if(r) then
coroutine.yield(r)
end
yaml_str = ""
elseif (line) then
yaml_str = yaml_str .. "\n" .. line
elseif(yaml_str) then
local r = lyaml.load(yaml_str)
if (r) then
coroutine.yield(r)
end
break
else
break
end
end
end
function load_file(fname)
local file = io.open(fname, "r")
local co = coroutine.create(function () file_loader(file) end)
return function () -- iterator
local code, res = coroutine.resume(co)
return res
end
end