main.lua

Mon, 07 Sep 2015 14:32:17 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Mon, 07 Sep 2015 14:32:17 +0100
changeset 13
553ea77aa2e7
parent 7
ecac723bb6e1
child 14
ad0dd3d45edc
permissions
-rwxr-xr-x

main: Add current script as a property of objects

#!/usr/bin/env lua5.1

local parser = require "scansion.parser";

io.input(arg[1]);
local script_data = io.read("*a");

local script = assert(parser.parse(script_data));

local c = 0;
for name, object in pairs(script.objects) do
	local o = require("scansion.objects."..object.type);
	object.handler = o;
	object.script = script;
	o._validate(object);
	c = c + 1;
end

print("Script defines "..c.." objects, and "..#script.actions.." actions");

local verse = require "verse";
require "util.logger";
local async = require "scansion.async";

local runner = async.runner(function ()
	print("f")
	for _, action in pairs(script.actions) do
		local object = script.objects[action.object_name];
		local handler = object.handler;
		assert(handler[action.action], "Objects of type '"..object.type.."' do not support action '"..action.action.."'");
		print(object.name, action.action.."...");
		handler[action.action](object, action.extra);
	end
end);

runner:run(true);
print("runner paused")

verse.loop()

mercurial