summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--life.lua15
1 files changed, 13 insertions, 2 deletions
diff --git a/life.lua b/life.lua
index 127974b..fca6d4c 100644
--- a/life.lua
+++ b/life.lua
@@ -140,12 +140,13 @@ function gol.apply_rule (cell, cnt, rule, fade, keep)
return new
end
+gol.formats = {}
-function gol.parse_file (fname)
+gol.formats[".gol"] = function (fname)
local tmp = {} -- return an array
local len -- check for equal line length
- if fname:sub(-4,-1) ~= ".gol" then -- check extension
+ if fname:sub(-4,-1) ~= ".gol" then
fname = fname .. ".gol"
end
@@ -177,6 +178,16 @@ function gol.parse_file (fname)
end
end
+
+function gol.parse_file (fname)
+ local p_suf = P"." * (1-P".")^3 * -P(1)
+ local p_fn = (1-p_suf)^1 * C(p_suf)
+ local suffix = p_fn:match(fname) or ".gol" -- assume .gol format as default
+
+ return gol.formats[suffix] ( fname )
+end
+
+
--- Computing single lines and whole frames and intervals thereof
function gol.next_line (rows, rule)