source: trunk/essentials/dev-lang/python/Tools/modulator/EXAMPLE.py@ 3951

Last change on this file since 3951 was 3225, checked in by bird, 19 years ago

Python 2.5

File size: 1.3 KB
Line 
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.
6
7import genmodule
8
9#
10# Generate code for a simple object with a method called sample
11
12o = genmodule.object()
13o.name = 'simple object'
14o.abbrev = 'simp'
15o.methodlist = ['sample']
16o.funclist = ['new']
17
18#
19# Generate code for an object that looks numberish
20#
21o2 = genmodule.object()
22o2.name = 'number-like object'
23o2.abbrev = 'nl'
24o2.typelist = ['tp_as_number']
25o2.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#
32o3 = genmodule.object()
33o3.name = 'over-the-top object'
34o3.abbrev = 'ot'
35o3.methodlist = ['method1', 'method2']
36o3.funclist = ['new', 'tp_dealloc', 'tp_print', 'tp_getattr', 'tp_setattr',
37 'tp_compare', 'tp_repr', 'tp_hash']
38o3.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#
45m = genmodule.module()
46m.name = 'sample'
47m.abbrev = 'sample'
48m.methodlist = ['newsimple', 'newnumberish', 'newott']
49m.objects = [o, o2, o3]
50
51fp = open('EXAMPLEmodule.c', 'w')
52genmodule.write(fp, m)
53fp.close()
Note: See TracBrowser for help on using the repository browser.