From The Compiler, 8 Years ago, written in Python.
Embed
  1.  
  2.     def extension_add_event(self, code, evt, name = None):
  3.         """extension_add_event(code, evt, [name])
  4.  
  5.        Add an extension event.  CODE is the numeric code, and EVT is
  6.        the event class.  EVT will be cloned, and the attribute _code
  7.        of the new event class will be set to CODE.
  8.  
  9.        If NAME is ommitted, it will be set to the name of EVT.  This
  10.        name is used to insert an entry in the DictWrapper
  11.        extension_event.
  12.        """
  13.  
  14.         newevt = new.classobj(evt.__name__, evt.__bases__,
  15.                               evt.__dict__.copy())
  16.         newevt._code = code
  17.  
  18.         self.display.add_extension_event(code, newevt)
  19.  
  20.         if name is None:
  21.             name = evt.__name__
  22.  
  23.         setattr(self.extension_event, name, code)