summaryrefslogtreecommitdiff
path: root/life.lua
diff options
context:
space:
mode:
Diffstat (limited to 'life.lua')
-rw-r--r--life.lua11
1 files changed, 8 insertions, 3 deletions
diff --git a/life.lua b/life.lua
index a760804..42a17bd 100644
--- a/life.lua
+++ b/life.lua
@@ -41,7 +41,7 @@ end
-- Modified to match left and right of one separator only.
function gol.helpers.split_once (s, sep)
local utfchar = gol.helpers.utfchar
- sep = P(sep)
+ sep = S(sep)
local left = C((1 - sep)^0)
local right = C((utfchar)^0)
local p = Ct(left * sep * right)
@@ -67,12 +67,13 @@ function gol.helpers.dead_row(len)
return row
end
--- Read rules of type "B3/S23"
+-- Read rules of type "B3[/.-]S23"
-- => “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 b_s = help.split_once (raw_rule, "/.-")
local tmp_b = help.strip(b_s[1], "B")
local tmp_s = help.strip(b_s[2], "S")
@@ -145,6 +146,10 @@ function gol.parse_file (fname)
local tmp = {} -- return an array
local len -- check for equal line length
+ if fname:sub(-4,-1) ~= ".gol" then -- check extension
+ fname = fname .. ".gol"
+ 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