Guido van Rossum | d211220 | 1995-03-02 14:05:29 +0000 | [diff] [blame] | 1 | # |
| 2 | # Example input file for modulator if you don't have tk. |
| 3 | # |
| 4 | # You may also have to strip some imports out of modulator to make |
| 5 | # it work. |
Jack Jansen | 52e0299 | 1995-05-16 13:43:09 +0000 | [diff] [blame] | 6 | |
| 7 | import genmodule |
| 8 | |
Guido van Rossum | d211220 | 1995-03-02 14:05:29 +0000 | [diff] [blame] | 9 | # |
| 10 | # Generate code for a simple object with a method called sample |
| 11 | |
| 12 | o = genmodule.object() |
| 13 | o.name = 'simple object' |
| 14 | o.abbrev = 'simp' |
| 15 | o.methodlist = ['sample'] |
| 16 | o.funclist = ['new'] |
| 17 | |
| 18 | # |
| 19 | # Generate code for an object that looks numberish |
| 20 | # |
| 21 | o2 = genmodule.object() |
| 22 | o2.name = 'number-like object' |
| 23 | o2.abbrev = 'nl' |
| 24 | o2.typelist = ['tp_as_number'] |
| 25 | o2.funclist = ['new', 'tp_repr', 'tp_compare'] |
| 26 | |
| 27 | # |
| 28 | # Generate code for a method with a full complement of functions, |
| 29 | # some methods, accessible as sequence and allowing structmember.c type |
| 30 | # structure access as well. |
| 31 | # |
| 32 | o3 = genmodule.object() |
| 33 | o3.name = 'over-the-top object' |
| 34 | o3.abbrev = 'ot' |
| 35 | o3.methodlist = ['method1', 'method2'] |
| 36 | o3.funclist = ['new', 'tp_dealloc', 'tp_print', 'tp_getattr', 'tp_setattr', |
Martin v. Löwis | 23b44a3 | 2003-10-24 20:09:23 +0000 | [diff] [blame] | 37 | 'tp_compare', 'tp_repr', 'tp_hash'] |
Guido van Rossum | d211220 | 1995-03-02 14:05:29 +0000 | [diff] [blame] | 38 | o3.typelist = ['tp_as_sequence', 'structure'] |
| 39 | |
| 40 | # |
| 41 | # Now generate code for a module that incorporates these object types. |
| 42 | # Also add the boilerplates for functions to create instances of each |
| 43 | # type. |
| 44 | # |
| 45 | m = genmodule.module() |
| 46 | m.name = 'sample' |
| 47 | m.abbrev = 'sample' |
| 48 | m.methodlist = ['newsimple', 'newnumberish', 'newott'] |
| 49 | m.objects = [o, o2, o3] |
Jack Jansen | 52e0299 | 1995-05-16 13:43:09 +0000 | [diff] [blame] | 50 | |
| 51 | fp = open('EXAMPLEmodule.c', 'w') |
| 52 | genmodule.write(fp, m) |
| 53 | fp.close() |