/Tools/modulator/EXAMPLE.py

http://unladen-swallow.googlecode.com/ · Python · 53 lines · 26 code · 7 blank · 20 comment · 0 complexity · 8ce7e36a5aa9cb002bd21d23d35f20cb MD5 · raw file

  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. import genmodule
  7. #
  8. # Generate code for a simple object with a method called sample
  9. o = genmodule.object()
  10. o.name = 'simple object'
  11. o.abbrev = 'simp'
  12. o.methodlist = ['sample']
  13. o.funclist = ['new']
  14. #
  15. # Generate code for an object that looks numberish
  16. #
  17. o2 = genmodule.object()
  18. o2.name = 'number-like object'
  19. o2.abbrev = 'nl'
  20. o2.typelist = ['tp_as_number']
  21. o2.funclist = ['new', 'tp_repr', 'tp_compare']
  22. #
  23. # Generate code for a method with a full complement of functions,
  24. # some methods, accessible as sequence and allowing structmember.c type
  25. # structure access as well.
  26. #
  27. o3 = genmodule.object()
  28. o3.name = 'over-the-top object'
  29. o3.abbrev = 'ot'
  30. o3.methodlist = ['method1', 'method2']
  31. o3.funclist = ['new', 'tp_dealloc', 'tp_print', 'tp_getattr', 'tp_setattr',
  32. 'tp_compare', 'tp_repr', 'tp_hash']
  33. o3.typelist = ['tp_as_sequence', 'structure']
  34. #
  35. # Now generate code for a module that incorporates these object types.
  36. # Also add the boilerplates for functions to create instances of each
  37. # type.
  38. #
  39. m = genmodule.module()
  40. m.name = 'sample'
  41. m.abbrev = 'sample'
  42. m.methodlist = ['newsimple', 'newnumberish', 'newott']
  43. m.objects = [o, o2, o3]
  44. fp = open('EXAMPLEmodule.c', 'w')
  45. genmodule.write(fp, m)
  46. fp.close()