Quick howto on converting modules

"Eric Davis" <[email protected]>
Newsgroups gmane.comp.games.mud.client.lyntin
Message-ID <[email protected]>
This looks better if you use a fixed width font.

--------------------------------------------------------------------------------
Here is a quick HOWTO on converting lyntin3 modules to lyntin4

There are several major steps


1. The imports

   The import structure for lyntin4 has changed.
   You must now import from the lyntin package
   
   E.G.
     Lyntin3:
       import ansi
       
     Lyntin4:
       from lyntin import ansi
       
   The modules in the lyntin directory are
     ansi, argparser, commandmanager, config, constants, 
     engine, event, exported, helpmanager, history,
     manager, net, session, utils
     
     These can be imported by using
       from lyntin import <modulename>
       
   The modules in the lyntin/modules directory are
     action, advanced, alias, deed, gag, highlight,
     logger, lyntincmds, manual, modutils, scheduler,
     speedwalk, substitute, tintincmds, variable
     
     These can be imported by using
       from lyntin.modules import <modulename>
       
   The modules in the lyntin/ui directory are
     base, message, textui, tkui
     
     These can be imported by using
       from lyntin.ui import <modulename>
       
       
2. Here is the harder part, the hook API has changed
   dramatically.
   
   Before the hooks passed all the vars in one big variable.
   
   Example, in Lyntin3 to setup and use a hook involved these
   steps:
   
   1.  Register the hook:
         hooks.mud_filter_hook.register(wcm.mudfilter, 80)

   2.  Then the function to handle this hook:
         def mudfilter(self, args):
         """
         mud_filter_hook function to perform windowing on data 
         that comes from the mud.
         """
         ses = args[0]
         text = args[-1]

         if not ses._ignoresubs:
           text = self.expand(ses, text)
         return texts
           
       The argument list was one big variable and you had to know
       that session was the first item and the text was the second
       item.
       
   In Lyntin4, all variables are put into a dictionary and passed
   to the function.  Also, the way to register with a hook has
   changed.
   
   So in Lyntin4 we have:
   
   1.  Register the hook:
         exported.hook_register("mud_filter_hook", wcm.mudfilter, 80)
      
   2.  Then the function to handle this hook: 
         def mudfilter(self, args):
         """
         mud_filter_hook function to perform windowing on data 
         that comes from the mud.
         """
         ses = args['session']
         text = args['dataadj']

         if exported.get_config("ignoresubs", ses, 0) == 0:
           text = self.expand(ses, text)
         return text
         
       The argument list is now a dictionary and makes the hook much
       easier to understand.

   The easiest way to find the arguments for a hook is to look through
   the source or check out the documentation on the web site.
   
     
3. Also, there is a new config manager. (you may have noticed this
   in the last example.)
   
   Config items are requested by this function:
     exported.get_config("config_item", session, defaultvalue)
     
   Config items that are supported in the first beta are:
     Commandline:
       datadir, moduledir, readfile, snoopdefault, ui
     Global:
       ansicolor, commandchar, debugmode, mudecho, promptdetection
     Session:
       ignoreactions, ignoresubs, snoop, speedwalk, verbatim
       
------------------------------------------------------------------------------------------------------


Eric Davis
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.