summaryrefslogtreecommitdiff
path: root/run.lua
diff options
context:
space:
mode:
Diffstat (limited to 'run.lua')
-rw-r--r--run.lua60
1 files changed, 44 insertions, 16 deletions
diff --git a/run.lua b/run.lua
index d8c18ad..357f350 100644
--- a/run.lua
+++ b/run.lua
@@ -31,12 +31,13 @@ end
require "life"
+local C, Cs, Ct, P, R, S, match = lpeg.C, lpeg.Cs, lpeg.Ct, lpeg.P, lpeg.R, lpeg.S, lpeg.match
+
local help = gol.helpers
-life = {}
-life.debug = 1
+debug = 1
-function life.get_args ()
+function get_args ()
gol.arg = arg
if gol.arg[-1] == "texlua" then
gol.machine = gol.arg[-1]
@@ -59,10 +60,9 @@ function life.get_args ()
return kv_args()
end
-function main ()
- local current = {}
- current.kv_args = life.get_args()
- current.file = current.kv_args.file or "10x10_glider.gol"
+function life (current)
+ -- how many frames should we draw?
+ current.n = current.kv_args.n or 40
-- sustaining dead cells
current.sustain = current.kv_args.sustain or 0 -- TODO
@@ -70,9 +70,9 @@ function main ()
-- check for debug flag
if tonumber(current.kv_args.debug) == 0 then
- life.debug = false
+ debug = false
else
- life.debug = current.kv_args.debug or life.debug
+ debug = current.kv_args.debug or debug
end
@@ -83,8 +83,8 @@ function main ()
current.rule = gol.parse_rule ("B3/S23") -- Conway's rule
end
- if life.debug then for n, a in pairs(current.kv_args) do print(n, a) end end
- if life.debug then for i, j in pairs(current.rule) do print(i, #j) end end
+ if debug then for n, a in pairs(current.kv_args) do print(n, a) end end
+ if debug then for i, j in pairs(current.rule) do print(i, #j) end end
-- read the initial state (get an array of strings)
if current.file then
@@ -94,22 +94,50 @@ function main ()
end
if current.init then
- if life.debug then
+ if debug then
gol.pre_frame(current.init)
end
- local many = gol.frames( current.init, current.rule, 40 )
+ local many = gol.frames( current.init, current.rule, current.n )
gol.pre_movie (many, true)
- --local lots = gol.frames( current.init, current.rule, 200 )
- --gol.pre_movie (lots, true)
else
io.write"\nCheck your input file for consistency, please.\n"
return 1
end
+ return 0
+end
-
+function eca(current)
+ local eca = require "eca"
+ -- how many lines to draw
+ current.n = tonumber(current.kv_args.n) or 30
+ current.aspect = tonumber(current.kv_args.aspect) or 3/4
+ current.rule = eca.gen_rule(tonumber(current.kv_args.rule) or 110)
+ current.from = eca.parse_file(current.kv_args.file)
+ current.framesize = math.floor(current.aspect * current.from:len())
+
+ for n=1,current.n,1 do
+ gol.pre_section(current.from:len(), n)
+ eca.successive(current)
+ end
return 0
end
+function main ()
+ local current = {}
+ current.kv_args = get_args()
+ current.file = current.kv_args.file or "10x10_glider.gol"
+
+ local p_suf = P"." * (1-P".")^3 * -P(1)
+ local p_fn = (1-p_suf)^1 * C(p_suf)
+ local suffix = p_fn:match(current.file) or ".gol" -- assume .gol format as default
+
+ if suffix == ".eca" then
+ return eca(current)
+ else
+ return life(current)
+ end
+end
+
if not context then
return main()
end