annotate pymonkey.c @ 37:d4efcbb06964

Added a new PYM_JSFunction type, PYM_JSContext.define_property(), and PYM_JSContext.new_function(). Also fixed a memory leak.
author Atul Varma <varmaa@toolness.com>
date Thu, 02 Jul 2009 22:42:31 -0700
parents 21045074139f
children bc4263c6ae82
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
29eaa1fceff1 Moved definition of undefined type into a separate module.
Atul Varma <varmaa@toolness.com>
parents: 9
diff changeset
1 #include "undefined.h"
11
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents: 10
diff changeset
2 #include "runtime.h"
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents: 10
diff changeset
3 #include "context.h"
13
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents: 11
diff changeset
4 #include "object.h"
37
d4efcbb06964 Added a new PYM_JSFunction type, PYM_JSContext.define_property(), and PYM_JSContext.new_function(). Also fixed a memory leak.
Atul Varma <varmaa@toolness.com>
parents: 27
diff changeset
5 #include "function.h"
11
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents: 10
diff changeset
6 #include "utils.h"
8
6647870380cc Added support for undefined.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
7
0
21aa6e3abb49 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
8 static PyMethodDef PYM_methods[] = {
21aa6e3abb49 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
9 {NULL, NULL, 0, NULL}
21aa6e3abb49 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
10 };
21aa6e3abb49 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
11
21aa6e3abb49 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
12 PyMODINIT_FUNC
21aa6e3abb49 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
13 initpymonkey(void)
21aa6e3abb49 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
14 {
21aa6e3abb49 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
15 PyObject *module;
21aa6e3abb49 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
16
21aa6e3abb49 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
17 module = Py_InitModule("pymonkey", PYM_methods);
21aa6e3abb49 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
18 if (module == NULL)
21aa6e3abb49 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
19 return;
21aa6e3abb49 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
20
8
6647870380cc Added support for undefined.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
21 if (PyType_Ready(&PYM_undefinedType) < 0)
6647870380cc Added support for undefined.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
22 return;
6647870380cc Added support for undefined.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
23
6647870380cc Added support for undefined.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
24 Py_INCREF(PYM_undefined);
6647870380cc Added support for undefined.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
25 PyModule_AddObject(module, "undefined", PYM_undefined);
6647870380cc Added support for undefined.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
26
0
21aa6e3abb49 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
27 PYM_error = PyErr_NewException("pymonkey.error", NULL, NULL);
21aa6e3abb49 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
28 Py_INCREF(PYM_error);
21aa6e3abb49 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
29 PyModule_AddObject(module, "error", PYM_error);
9
032cfc448079 Added pymonkey.Runtime and pymonkey.Context as new types.
Atul Varma <varmaa@toolness.com>
parents: 8
diff changeset
30
032cfc448079 Added pymonkey.Runtime and pymonkey.Context as new types.
Atul Varma <varmaa@toolness.com>
parents: 8
diff changeset
31 if (!PyType_Ready(&PYM_JSRuntimeType) < 0)
032cfc448079 Added pymonkey.Runtime and pymonkey.Context as new types.
Atul Varma <varmaa@toolness.com>
parents: 8
diff changeset
32 return;
032cfc448079 Added pymonkey.Runtime and pymonkey.Context as new types.
Atul Varma <varmaa@toolness.com>
parents: 8
diff changeset
33
032cfc448079 Added pymonkey.Runtime and pymonkey.Context as new types.
Atul Varma <varmaa@toolness.com>
parents: 8
diff changeset
34 Py_INCREF(&PYM_JSRuntimeType);
032cfc448079 Added pymonkey.Runtime and pymonkey.Context as new types.
Atul Varma <varmaa@toolness.com>
parents: 8
diff changeset
35 PyModule_AddObject(module, "Runtime", (PyObject *) &PYM_JSRuntimeType);
032cfc448079 Added pymonkey.Runtime and pymonkey.Context as new types.
Atul Varma <varmaa@toolness.com>
parents: 8
diff changeset
36
032cfc448079 Added pymonkey.Runtime and pymonkey.Context as new types.
Atul Varma <varmaa@toolness.com>
parents: 8
diff changeset
37 if (!PyType_Ready(&PYM_JSContextType) < 0)
032cfc448079 Added pymonkey.Runtime and pymonkey.Context as new types.
Atul Varma <varmaa@toolness.com>
parents: 8
diff changeset
38 return;
032cfc448079 Added pymonkey.Runtime and pymonkey.Context as new types.
Atul Varma <varmaa@toolness.com>
parents: 8
diff changeset
39
032cfc448079 Added pymonkey.Runtime and pymonkey.Context as new types.
Atul Varma <varmaa@toolness.com>
parents: 8
diff changeset
40 Py_INCREF(&PYM_JSContextType);
032cfc448079 Added pymonkey.Runtime and pymonkey.Context as new types.
Atul Varma <varmaa@toolness.com>
parents: 8
diff changeset
41 PyModule_AddObject(module, "Context", (PyObject *) &PYM_JSContextType);
13
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents: 11
diff changeset
42
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents: 11
diff changeset
43 if (!PyType_Ready(&PYM_JSObjectType) < 0)
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents: 11
diff changeset
44 return;
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents: 11
diff changeset
45
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents: 11
diff changeset
46 Py_INCREF(&PYM_JSObjectType);
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents: 11
diff changeset
47 PyModule_AddObject(module, "Object", (PyObject *) &PYM_JSObjectType);
37
d4efcbb06964 Added a new PYM_JSFunction type, PYM_JSContext.define_property(), and PYM_JSContext.new_function(). Also fixed a memory leak.
Atul Varma <varmaa@toolness.com>
parents: 27
diff changeset
48
d4efcbb06964 Added a new PYM_JSFunction type, PYM_JSContext.define_property(), and PYM_JSContext.new_function(). Also fixed a memory leak.
Atul Varma <varmaa@toolness.com>
parents: 27
diff changeset
49 PYM_JSFunctionType.tp_base = &PYM_JSObjectType;
d4efcbb06964 Added a new PYM_JSFunction type, PYM_JSContext.define_property(), and PYM_JSContext.new_function(). Also fixed a memory leak.
Atul Varma <varmaa@toolness.com>
parents: 27
diff changeset
50 if (!PyType_Ready(&PYM_JSFunctionType) < 0)
d4efcbb06964 Added a new PYM_JSFunction type, PYM_JSContext.define_property(), and PYM_JSContext.new_function(). Also fixed a memory leak.
Atul Varma <varmaa@toolness.com>
parents: 27
diff changeset
51 return;
d4efcbb06964 Added a new PYM_JSFunction type, PYM_JSContext.define_property(), and PYM_JSContext.new_function(). Also fixed a memory leak.
Atul Varma <varmaa@toolness.com>
parents: 27
diff changeset
52
d4efcbb06964 Added a new PYM_JSFunction type, PYM_JSContext.define_property(), and PYM_JSContext.new_function(). Also fixed a memory leak.
Atul Varma <varmaa@toolness.com>
parents: 27
diff changeset
53 Py_INCREF(&PYM_JSFunctionType);
d4efcbb06964 Added a new PYM_JSFunction type, PYM_JSContext.define_property(), and PYM_JSContext.new_function(). Also fixed a memory leak.
Atul Varma <varmaa@toolness.com>
parents: 27
diff changeset
54 PyModule_AddObject(module, "Function", (PyObject *) &PYM_JSFunctionType);
0
21aa6e3abb49 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
55 }