Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(307)

Side by Side Diff: resources/slides_utils.lua

Issue 679903002: add saveLayer to lua (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « resources/slides.lua ('k') | src/utils/SkLua.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 function tostr(t)
2 local str = ""
3 for k, v in next, t do
4 if #str > 0 then
5 str = str .. ", "
6 end
7 if type(k) == "number" then
8 str = str .. "[" .. k .. "] = "
9 else
10 str = str .. tostring(k) .. " = "
11 end
12 if type(v) == "table" then
13 str = str .. "{ " .. tostr(v) .. " }"
14 elseif type(v) == "string" then
15 str = str .. '"' .. v .. '"'
16 else
17 str = str .. tostring(v)
18 end
19 end
20 return str
21 end
22
23 function trim_ws(s)
24 return s:match("^%s*(.*)")
25 end
26
27 function count_hypens(s)
28 local leftover = s:match("^-*(.*)")
29 return string.len(s) - string.len(leftover)
30 end
31
32 function parse_file(file)
33 local slides = {}
34 local block = {}
35
36 for line in file:lines() do
37 local s = trim_ws(line)
38 if #s == 0 then -- done with a block
39 if #block > 0 then
40 slides[#slides + 1] = block
41 block = {}
42 end
43 else
44 local n = count_hypens(s)
45 block[#block + 1] = {
46 indent = n,
47 text = trim_ws(s:sub(n + 1, -1))
48 }
49 end
50 end
51 return slides
52 end
53
54 function pretty_print_slide(slide)
55 io.write("{\n")
56 for i = 1, #slide do
57 local node = slide[i]
58 for j = 0, node.indent do
59 io.write(" ")
60 end
61 io.write("{ ")
62 io.write(tostr(node))
63 io.write(" },\n")
64 end
65 io.write("},\n")
66 end
67
68 function pretty_print_slides(slides)
69 io.write("gSlides = {\n")
70 for i = 1, #slides do
71 pretty_print_slide(slides[i])
72 end
73 io.write("}\n")
74 end
75
OLDNEW
« no previous file with comments | « resources/slides.lua ('k') | src/utils/SkLua.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698