summaryrefslogtreecommitdiff
path: root/life.lua
diff options
context:
space:
mode:
Diffstat (limited to 'life.lua')
-rw-r--r--life.lua25
1 files changed, 18 insertions, 7 deletions
diff --git a/life.lua b/life.lua
index 42a17bd..127974b 100644
--- a/life.lua
+++ b/life.lua
@@ -71,7 +71,6 @@ end
-- => “birth” of a new cell if exactly 3 adjacent cells are “alive”
-- => “staying alive” of cells with two or three adjacent “live” cells
function gol.parse_rule (raw_rule)
- print("HERE!!>>>>>>>>>>> "..raw_rule)
local help = gol.helpers
local b_s = help.split_once (raw_rule, "/.-")
local tmp_b = help.strip(b_s[1], "B")
@@ -151,19 +150,31 @@ function gol.parse_file (fname)
end
local file = assert(io.open(fname, "r"), "Not a file: " .. fname)
- for line in file:lines() do
- if not len then len = string.len(line) end
+ local data = file:read("*all")
+ file:close()
- if len ~= string.len(line) then
+ local cell = R"09" + P"D"
+ local nl = Cs(P"\n") / ""
+ local line = Cs(cell^1) / function (l)
+ if not len then len = string.len(l) end
+ if len ~= string.len(l) then
-- inconsistent horizontal sizes; kill off program
return nil
else
- table.insert(tmp, line)
+ table.insert(tmp,l)
end
end
- file:close()
- return tmp
+ local gol_parser = Cs(line * (nl + line)^0)
+
+ if gol_parser:match(data) then
+ if context then
+ context.writestatus("simpleslides", "Sucessfully loaded frame from "..fname..".")
+ end
+ return tmp
+ else
+ return false
+ end
end
--- Computing single lines and whole frames and intervals thereof