blob: 070a6222cbbf3eb50672420946a6a9a8dc730d43 [file] [log] [blame]
Guido van Rossum1984f1e1992-08-04 12:41:02 +00001/***********************************************************
2Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
3Netherlands.
4
5 All Rights Reserved
6
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting documentation, and that the names of Stichting Mathematisch
12Centrum or CWI not be used in advertising or publicity pertaining to
13distribution of the software without specific, written prior permission.
14
15STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21OF 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
33static object *
34xx_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
49static object *
50xx_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
65static 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
74void
75initxx()
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}