Debian Codegraph @

terps/tads/tads3/test/data/undef.t

raw
1 #include <tads.h>
2 #include <lookup.h>
3
4 property propNotDefined;
5 export propNotDefined;
6
7 object template "name";
8
9 symtab: PreinitObject
10 execute()
11 {
12 local gsym;
13
14 /* get the global symbol table */
15 gsym = t3GetGlobalSymbols();
16
17 /* create a table for mapping property ID's to names */
18 proptab_ = new LookupTable(
19 gsym.getBucketCount(), gsym.getEntryCount());
20
21 /* build the table */
22 gsym.forEachAssoc(new function(key, val)
23 {
24 /*
25 * if it's a property, add it to the property lookup table
26 * (the property ID is the key, and the name is the value,
27 * so it provides the reverse of the system global symbol
28 * table's mapping)
29 */
30 if (dataType(val) == TypeProp)
31 proptab_[val] = key;
32 });
33 }
34 proptab_ = nil
35
36 getPropName(prop)
37 {
38 local name;
39
40 /* look up the name in our property ID mapping table */
41 name = proptab_[prop];
42
43 /* if it's defined, return it; otherwise, provide a default name */
44 return (name != nil ? name : '<undefined>');
45 }
46 ;
47
48 class Item: object
49 propNotDefined(prop, [args])
50 {
51 local first;
52
53 "Undefined: <<name>>.<<symtab.getPropName(prop)>>(";
54 first = true;
55 foreach(local x in args)
56 {
57 /*
58 * show a comma after the previous arg, if there was a
59 * previous arg
60 */
61 if (!first)
62 {
63 /* it's not the first, so there's a previous */
64 ", ";
65 }
66
67 /* show this one */
68 "<<x>>";
69
70 /* the next one won't be the first, so clear the flag */
71 first = nil;
72 }
73 ")\n";
74 }
75 ;
76
77 obj1: Item "obj1"
78 a(x) { "This is obj1.a(<<x>>)\n"; }
79 b(x, y) { "This is obj1.b(<<x>>, <<y>>)\n"; }
80 ;
81
82
83 obj2: Item "obj2"
84 a(x) { "This is obj2.a(<<x>>)\n"; }
85 ;
86
87 main(args)
88 {
89 obj1.a(1);
90 obj1.b(2, 3);
91 obj2.a(4);
92 obj2.b(5, 6);
93 }
94