|
From: David B. <dav...@us...> - 2004-12-18 22:31:31
|
Update of /cvsroot/frontierkernel/Frontier/Common/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14562 Modified Files: Tag: sidewinder-branch langpython.c Log Message: added top level UserTalk object (aliases: usertalk, ut) for access to scripts along system.path Index: langpython.c =================================================================== RCS file: /cvsroot/frontierkernel/Frontier/Common/source/langpython.c,v retrieving revision 1.2.4.28 retrieving revision 1.2.4.29 diff -C2 -d -r1.2.4.28 -r1.2.4.29 *** langpython.c 5 Dec 2004 18:02:06 -0000 1.2.4.28 --- langpython.c 18 Dec 2004 22:31:20 -0000 1.2.4.29 *************** *** 575,578 **** --- 575,579 ---- static PyObject *newInternalValueObject(tyvaluetype vt); static PyObject *newExternalValueObject(tyexternalid ei); + static PyObject *newUserTalkObject(void); static time_t currentCookie = (time_t)0; *************** *** 1548,1560 **** // call the script - //releasepythonlock(); if (!langexternalgetquotedpath(self->parent, self->name, funcname)) { - //getpythonlock(); goto exitnone; } if (!langrunscript(funcname, ¶ms, nil, &retval)) { - //getpythonlock(); goto exitnone; } --- 1549,1558 ---- *************** *** 1600,1603 **** --- 1598,1677 ---- }; + typedef struct { + PyObject_HEAD + } frontier_UserTalkObject; + + static PyObject * + UserTalk_getattr(frontier_UserTalkObject *self, char *name) { + PyObject *result; + + getpythonlock(); + result = fetchAux(name); + releasepythonlock(); + + return result; + } + + static PyObject * + UserTalk_getItem(frontier_UserTalkObject *self, PyObject *key) { + char *keyName; + PyObject *result; + + getpythonlock(); + keyName = PyString_AsString(PyObject_Str(key)); + result = fetchAux(keyName); + releasepythonlock(); + + return result; + } + + PyMappingMethods utmapping = { + (inquiry)0, + (binaryfunc)UserTalk_getItem, + (objobjargproc)0 + }; + + static PyTypeObject frontier_UserTalkType = { + PyObject_HEAD_INIT(NULL) + 0, /*ob_size*/ + "frontier.UserTalk", /*tp_name*/ + sizeof(frontier_UserTalkObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + 0, /*tp_dealloc*/ + 0, /*tp_print*/ + (getattrfunc)UserTalk_getattr, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + &utmapping, /*tp_as_mapping*/ + 0, /*tp_hash */ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT, /*tp_flags*/ + "Frontier UserTalk objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ + }; + static boolean addType(PyObject *m, PyTypeObject *to, char *name) { *************** *** 1629,1633 **** addType(m, &frontier_ScriptType, "Script") && addType(m, &frontier_InternalValueType, "InternalValue") && ! addType(m, &frontier_ExternalValueType, "ExternalValue"); if (!result) --- 1703,1708 ---- addType(m, &frontier_ScriptType, "Script") && addType(m, &frontier_InternalValueType, "InternalValue") && ! addType(m, &frontier_ExternalValueType, "ExternalValue") && ! addType(m, &frontier_UserTalkType, "UserTalk"); if (!result) *************** *** 1640,1643 **** --- 1715,1723 ---- safeaddobject(m, "websites", fetchAux("websites")); safeaddobject(m, "workspace", fetchAux("workspace")); + + PyObject *ut = newUserTalkObject(); + safeaddobject(m, "ut", ut); + safeaddobject(m, "usertalk", ut); + safeaddobject(m, "UserTalk", ut); return true; *************** *** 1712,1716 **** PyObject *class; frontier_ExternalValue *obj; ! class = PyObject_GetAttrString(frontierModule, "ExternalValue"); obj = PyObject_New(frontier_ExternalValue, (PyTypeObject *)class); --- 1792,1796 ---- PyObject *class; frontier_ExternalValue *obj; ! class = PyObject_GetAttrString(frontierModule, "ExternalValue"); obj = PyObject_New(frontier_ExternalValue, (PyTypeObject *)class); *************** *** 1720,1723 **** --- 1800,1814 ---- } + static PyObject * + newUserTalkObject() { + PyObject *class; + frontier_UserTalkObject *obj; + + class = PyObject_GetAttrString(frontierModule, "UserTalk"); + obj = PyObject_New(frontier_UserTalkObject, (PyTypeObject *)class); + + return (PyObject *)obj; + } + /* the frontier kernel verb side */ |