comparison src/pydermonkey.cpp @ 170:dd32a92f6b4f

Initial attempt at renaming pymonkey to pydermonkey.
author Atul Varma <varmaa@toolness.com>
date Tue, 01 Sep 2009 03:07:24 -0700
parents src/pymonkey.cpp@657afb7307eb
children
comparison
equal deleted inserted replaced
169:2b98d4643c44 170:dd32a92f6b4f
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 *
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Original Code is Pydermonkey.
15 *
16 * The Initial Developer of the Original Code is Mozilla.
17 * Portions created by the Initial Developer are Copyright (C) 2007
18 * the Initial Developer. All Rights Reserved.
19 *
20 * Contributor(s):
21 * Atul Varma <atul@mozilla.com>
22 *
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
34 *
35 * ***** END LICENSE BLOCK ***** */
36
37 #include "undefined.h"
38 #include "runtime.h"
39 #include "context.h"
40 #include "object.h"
41 #include "function.h"
42 #include "script.h"
43 #include "utils.h"
44
45 static PyObject *
46 PYM_getDebugInfo(PyObject *self, PyObject *args)
47 {
48 PyObject *info = Py_BuildValue("{sI}",
49 "runtime_count", PYM_getJSRuntimeCount());
50 return info;
51 }
52
53 static PyMethodDef PYM_methods[] = {
54 {"get_debug_info", PYM_getDebugInfo, METH_VARARGS,
55 "Get debugging information about the module."},
56 {NULL, NULL, 0, NULL}
57 };
58
59 PyMODINIT_FUNC
60 initpydermonkey(void)
61 {
62 PyObject *module;
63
64 module = Py_InitModule("pydermonkey", PYM_methods);
65 if (module == NULL)
66 return;
67
68 if (PyType_Ready(&PYM_undefinedType) < 0)
69 return;
70
71 PYM_undefined = PyObject_New(PYM_undefinedObject, &PYM_undefinedType);
72 if (PYM_undefined == NULL)
73 return;
74 Py_INCREF(PYM_undefined);
75 PyModule_AddObject(module, "undefined", (PyObject *) PYM_undefined);
76
77 PYM_error = PyErr_NewException("pydermonkey.error", NULL, NULL);
78 Py_INCREF(PYM_error);
79 PyModule_AddObject(module, "error", PYM_error);
80
81 if (!PyType_Ready(&PYM_JSRuntimeType) < 0)
82 return;
83
84 Py_INCREF(&PYM_JSRuntimeType);
85 PyModule_AddObject(module, "Runtime", (PyObject *) &PYM_JSRuntimeType);
86
87 if (!PyType_Ready(&PYM_JSContextType) < 0)
88 return;
89
90 Py_INCREF(&PYM_JSContextType);
91 PyModule_AddObject(module, "Context", (PyObject *) &PYM_JSContextType);
92
93 if (!PyType_Ready(&PYM_JSObjectType) < 0)
94 return;
95
96 Py_INCREF(&PYM_JSObjectType);
97 PyModule_AddObject(module, "Object", (PyObject *) &PYM_JSObjectType);
98
99 PYM_JSFunctionType.tp_base = &PYM_JSObjectType;
100 if (!PyType_Ready(&PYM_JSFunctionType) < 0)
101 return;
102
103 Py_INCREF(&PYM_JSFunctionType);
104 PyModule_AddObject(module, "Function", (PyObject *) &PYM_JSFunctionType);
105
106 PYM_JSScriptType.tp_base = &PYM_JSObjectType;
107 if (!PyType_Ready(&PYM_JSScriptType) < 0)
108 return;
109
110 Py_INCREF(&PYM_JSScriptType);
111 PyModule_AddObject(module, "Script", (PyObject *) &PYM_JSScriptType);
112 }