From 0424a2a795fb3da1c18284e2c86dc76c9ac4c0d3 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Fri, 13 Aug 2010 12:00:22 +0200 Subject: config files. frame loading now via LPEG. --- life.lua | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'life.lua') 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 -- cgit v1.2.3