home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pyth_os2.zip / python-1.0.2 / Modules / xxmodule.c < prev    next >
C/C++ Source or Header  |  1994-01-02  |  2KB  |  93 lines

  1. /***********************************************************
  2. Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
  3. Amsterdam, The Netherlands.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the names of Stichting Mathematisch
  12. Centrum or CWI not be used in advertising or publicity pertaining to
  13. distribution of the software without specific, written prior permission.
  14.  
  15. STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  16. THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  18. FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  20. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  21. OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  
  23. ******************************************************************/
  24.  
  25. /* xx module */
  26.  
  27. #include "allobjects.h"
  28. #include "modsupport.h"
  29.  
  30.  
  31. /* Function of two integers returning integer */
  32.  
  33. static object *
  34. xx_foo(self, args)
  35.     object *self; /* Not used */
  36.     object *args;
  37. {
  38.     long i, j;
  39.     long res;
  40.     if (!getargs(args, "(ll)", &i, &j))
  41.         return NULL;
  42.     res = i+j; /* XXX Do something here */
  43.     return newintobject(res);
  44. }
  45.  
  46.  
  47. /* Function of no arguments returning None */
  48.  
  49. static object *
  50. xx_bar(self, args)
  51.     object *self; /* Not used */
  52.     object *args;
  53. {
  54.     int i, j;
  55.     if (!getnoarg(args))
  56.         return NULL;
  57.     /* XXX Do something here */
  58.     INCREF(None);
  59.     return None;
  60. }
  61.  
  62.  
  63. /* List of functions defined in the module */
  64.  
  65. static struct methodlist xx_methods[] = {
  66.     {"foo",        xx_foo},
  67.     {"bar",        xx_bar},
  68.     {NULL,        NULL}        /* sentinel */
  69. };
  70.  
  71.  
  72. /* Initialization function for the module (*must* be called initxx) */
  73.  
  74. void
  75. initxx()
  76. {
  77.     object *m, *d, *x;
  78.  
  79.     /* Create the module and add the functions */
  80.     m = initmodule("xx", xx_methods);
  81.  
  82.     /* Add some symbolic constants to the module */
  83.     d = getmoduledict(m);
  84.     x = newstringobject("xx.error");
  85.     dictinsert(d, "error", x);
  86.     x = newintobject(42L);
  87.     dictinsert(d, "magic", x);
  88.  
  89.     /* Check for errors */
  90.     if (err_occurred())
  91.         fatal("can't initialize module xx");
  92. }
  93.