//***************************************************************************** // local functions //***************************************************************************** void PyEvent_on_complete(void *owner, PyObject *tuple, const char *arg) { PyObject *PyOwner = NULL; PyObject *efunc = NULL; PyObject *edata = NULL; char *otype = NULL; // make sure we parse everything before we call the function if(PyArg_ParseTuple(tuple, "sOO", &otype, &efunc, &edata)) { if(!strcasecmp(otype, "char")) PyOwner = charGetPyFormBorrowed(owner); else if(!strcasecmp(otype, "room")) PyOwner = roomGetPyFormBorrowed(owner); else if(!strcasecmp(otype, "obj")) PyOwner = objGetPyFormBorrowed(owner); else PyOwner = Py_None; PyObject *ret = PyObject_CallFunction(efunc, "OOs", PyOwner, edata, arg); if(ret == NULL) log_pyerr("Error finishing Python event"); Py_XDECREF(ret); } // decrease the reference on our function and data, as well as our owner Py_XDECREF(tuple); }
// // Try running a script on the initiator bool try_reset_script(RESET_DATA *reset, void *initiator, int initiator_type, const char *locale) { PyObject *pyme = NULL; PyObject *dict = NULL; if(initiator_type == INITIATOR_ROOM) pyme = roomGetPyFormBorrowed(initiator); else if(initiator_type == INITIATOR_THEN_OBJ) pyme = objGetPyFormBorrowed(initiator); else if(initiator_type == INITIATOR_THEN_MOB) pyme = charGetPyFormBorrowed(initiator); else return FALSE; // build our dictionary and add ourself to it as 'me' dict = restricted_script_dict(); PyDict_SetItemString(dict, "me", pyme); // run the script run_script(dict, resetGetArg(reset), locale); // check to see if we had an error if(!last_script_ok()) log_pyerr("Reset script in locale %s terminated with an error:\r\n%s", locale, resetGetArg(reset)); // garbage collection and return our outcome Py_DECREF(dict); return last_script_ok(); }
PyObject *roomGetPyForm(ROOM_DATA *room) { PyObject *pyform = roomGetPyFormBorrowed(room); Py_INCREF(pyform); return pyform; }