Mercurial > repos > tabletprog
annotate scripttags.js @ 41:0558dad9d061
Add basic string support
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 11 Jul 2012 21:57:38 -0700 |
parents | 4d87c38404d6 |
children | 648659961e0e |
rev | line source |
---|---|
9
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 function compileAndRun(src) |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 { |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 var ast = parser.parse(src); |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 var js = ast.toJSModule(); |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 mainModule = eval(js)(); |
25
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
9
diff
changeset
|
7 if (mainModule.strue) { |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
9
diff
changeset
|
8 each(mainModule.strue, function(key, val) { |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
9
diff
changeset
|
9 if(val instanceof Function) { |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
9
diff
changeset
|
10 Boolean.prototype[key] = function() { |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
9
diff
changeset
|
11 return this.valueOf() ? mainModule.strue[key].apply(mainModule.strue, arguments) : mainModule.sfalse[key].apply(mainModule.sfalse, arguments); |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
9
diff
changeset
|
12 }; |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
9
diff
changeset
|
13 } |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
9
diff
changeset
|
14 }); |
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
9
diff
changeset
|
15 } |
9
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 mainModule.main(); |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 } |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 onReady(function() { |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 var tags = qall('script[type="text/tabletprog"]'); |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 for (var i = 0; i < tags.length; ++i) { |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 if (tags[i].src) { |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 get(tags[i].src, function(req) { |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 compileAndRun(req.responseText); |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 }); |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 } else { |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 compileAndRun(tags[i].innerHTML); |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 } |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 } |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 }); |