| 1 |
#include "tads.h" |
| 2 |
|
| 3 |
|
| 4 |
#define showParams(func) _showParams(#@func, func) |
| 5 |
_showParams(funcName, func) |
| 6 |
{ |
| 7 |
local args; |
| 8 |
|
| 9 |
/* get the function parameter information */ |
| 10 |
args = getFuncParams(func); |
| 11 |
|
| 12 |
/* show the name and the open paren */ |
| 13 |
"<<funcName>>("; |
| 14 |
|
| 15 |
/* list arguments - name them starting at 'a' (unicode=97) */ |
| 16 |
for (local i = 1, local nm = 97, local len = 1 ; |
| 17 |
i <= args[1] + args[2] ; ++i, ++nm) |
| 18 |
{ |
| 19 |
/* add a comma separator if this isn't the first one */ |
| 20 |
if (i != 1) |
| 21 |
", "; |
| 22 |
|
| 23 |
/* show this one's name (a, b, ...) */ |
| 24 |
"<<makeString(nm, len)>>"; |
| 25 |
|
| 26 |
/* add '?' if this one's optional (past the minimum count) */ |
| 27 |
if (i > args[1]) |
| 28 |
"?"; |
| 29 |
|
| 30 |
/* |
| 31 |
* if we've reached 'z' (unicode=122), go back to 'a' |
| 32 |
* and increase the length, so we get x, y, z, aa, bb, |
| 33 |
* cc, ..., zz, aaa, bbb, ... |
| 34 |
*/ |
| 35 |
if (nm == 122) |
| 36 |
{ |
| 37 |
/* go back to a minus one (we're about to increment) */ |
| 38 |
nm = 96; |
| 39 |
|
| 40 |
/* increase the length */ |
| 41 |
++len; |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
/* if it's varargs, add the varargs signifier */ |
| 46 |
if (args[3]) |
| 47 |
{ |
| 48 |
/* show a comma if there were other arguments */ |
| 49 |
if (args[1] != 0 || args[2] != 0) |
| 50 |
", "; |
| 51 |
|
| 52 |
/* show the varargs ellipsis */ |
| 53 |
"..."; |
| 54 |
} |
| 55 |
|
| 56 |
/* add the closing paren */ |
| 57 |
")"; |
| 58 |
} |
| 59 |
|
| 60 |
varfunc(a, b, ...) |
| 61 |
{ |
| 62 |
return a + b + argcount; |
| 63 |
} |
| 64 |
|
| 65 |
varfunc2(...) |
| 66 |
{ |
| 67 |
return argcount; |
| 68 |
} |
| 69 |
|
| 70 |
main(args) |
| 71 |
{ |
| 72 |
showParams(main); "\n"; |
| 73 |
showParams(varfunc); "\n"; |
| 74 |
showParams(varfunc2); "\n"; |
| 75 |
showParams(_showParams); "\n"; |
| 76 |
} |