main.lua

Sat, 05 Sep 2015 23:26:15 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Sat, 05 Sep 2015 23:26:15 +0100
changeset 7
ecac723bb6e1
parent 3
3cc860a893d2
child 13
553ea77aa2e7
permissions
-rwxr-xr-x

main: Run actions in async runner

0
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env lua5.1
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local parser = require "scansion.parser";
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 io.input(arg[1]);
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 local script_data = io.read("*a");
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 local script = assert(parser.parse(script_data));
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 local c = 0;
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 for name, object in pairs(script.objects) do
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 local o = require("scansion.objects."..object.type);
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 object.handler = o;
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 o._validate(object);
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 c = c + 1;
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 end
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 print("Script defines "..c.." objects, and "..#script.actions.." actions");
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19
7
ecac723bb6e1 main: Run actions in async runner
Matthew Wild <mwild1@gmail.com>
parents: 3
diff changeset
20 local verse = require "verse";
ecac723bb6e1 main: Run actions in async runner
Matthew Wild <mwild1@gmail.com>
parents: 3
diff changeset
21 require "util.logger";
ecac723bb6e1 main: Run actions in async runner
Matthew Wild <mwild1@gmail.com>
parents: 3
diff changeset
22 local async = require "scansion.async";
ecac723bb6e1 main: Run actions in async runner
Matthew Wild <mwild1@gmail.com>
parents: 3
diff changeset
23
ecac723bb6e1 main: Run actions in async runner
Matthew Wild <mwild1@gmail.com>
parents: 3
diff changeset
24 local runner = async.runner(function ()
ecac723bb6e1 main: Run actions in async runner
Matthew Wild <mwild1@gmail.com>
parents: 3
diff changeset
25 print("f")
ecac723bb6e1 main: Run actions in async runner
Matthew Wild <mwild1@gmail.com>
parents: 3
diff changeset
26 for _, action in pairs(script.actions) do
ecac723bb6e1 main: Run actions in async runner
Matthew Wild <mwild1@gmail.com>
parents: 3
diff changeset
27 local object = script.objects[action.object_name];
ecac723bb6e1 main: Run actions in async runner
Matthew Wild <mwild1@gmail.com>
parents: 3
diff changeset
28 local handler = object.handler;
ecac723bb6e1 main: Run actions in async runner
Matthew Wild <mwild1@gmail.com>
parents: 3
diff changeset
29 assert(handler[action.action], "Objects of type '"..object.type.."' do not support action '"..action.action.."'");
ecac723bb6e1 main: Run actions in async runner
Matthew Wild <mwild1@gmail.com>
parents: 3
diff changeset
30 print(object.name, action.action.."...");
ecac723bb6e1 main: Run actions in async runner
Matthew Wild <mwild1@gmail.com>
parents: 3
diff changeset
31 handler[action.action](object, action.extra);
ecac723bb6e1 main: Run actions in async runner
Matthew Wild <mwild1@gmail.com>
parents: 3
diff changeset
32 end
ecac723bb6e1 main: Run actions in async runner
Matthew Wild <mwild1@gmail.com>
parents: 3
diff changeset
33 end);
ecac723bb6e1 main: Run actions in async runner
Matthew Wild <mwild1@gmail.com>
parents: 3
diff changeset
34
ecac723bb6e1 main: Run actions in async runner
Matthew Wild <mwild1@gmail.com>
parents: 3
diff changeset
35 runner:run(true);
ecac723bb6e1 main: Run actions in async runner
Matthew Wild <mwild1@gmail.com>
parents: 3
diff changeset
36 print("runner paused")
3
3cc860a893d2 main: verse.loop()
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
37
3cc860a893d2 main: verse.loop()
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
38 verse.loop()

mercurial