| | 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 | modify 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 | class Item: object |
| | 78 | ; |
| | 79 | |
| | 80 | obj1: Item "obj1" |
| | 81 | a(x) { "This is obj1.a(<<x>>)\n"; } |
| | 82 | b(x, y) { "This is obj1.b(<<x>>, <<y>>)\n"; } |
| | 83 | ; |
| | 84 | |
| | 85 | |
| | 86 | obj2: Item "obj2" |
| | 87 | a(x) { "This is obj2.a(<<x>>)\n"; } |
| | 88 | ; |
| | 89 | |
| | 90 | main(args) |
| | 91 | { |
| | 92 | obj1.a(1); |
| | 93 | obj1.b(2, 3); |
| | 94 | obj2.a(4); |
| | 95 | obj2.b(5, 6); |
| | 96 | } |
| | 97 | |