view scripttags.js @ 68:3a169ebb3224

Change strategy for handling true and false to avoid some initialization order problems and improve performance. Add support for negative integer literals. Update samples to reflect true/false change.
author Mike Pavone <pavone@retrodev.com>
date Sat, 14 Jul 2012 16:14:01 -0700
parents 4d87c38404d6
children 648659961e0e
line wrap: on
line source


function compileAndRun(src)
{
	var ast = parser.parse(src);
	var js = ast.toJSModule();
	mainModule = eval(js)();
	if (mainModule.strue) {
		each(mainModule.strue, function(key, val) {
			if(val instanceof Function) {
				Boolean.prototype[key] = function() {
					return this.valueOf() ? mainModule.strue[key].apply(mainModule.strue, arguments) : mainModule.sfalse[key].apply(mainModule.sfalse, arguments);
				};
			}
		});
	}
	mainModule.main();
}

onReady(function() {
	var tags = qall('script[type="text/tabletprog"]');
	for (var i = 0; i < tags.length; ++i) {
		if (tags[i].src) {
			get(tags[i].src, function(req) {
				compileAndRun(req.responseText);
			});
		} else {
			compileAndRun(tags[i].innerHTML);
		}
	}
});