예제 #1
0
PyObject * wrapEntity(LocatedEntity * le)
{
    PyObject * wrapper;
    PythonWrapper * pw = dynamic_cast<PythonWrapper *>(le->script());
    if (pw == 0) {
        Entity * entity = dynamic_cast<Entity *>(le);
        if (entity != 0) {
          Character * ch_entity = dynamic_cast<Character *>(entity);
          if (ch_entity != 0) {
              PyEntity * pc = newPyCharacter();
              if (pc == NULL) {
                  return NULL;
              }
              pc->m_entity.c = ch_entity;
              wrapper = (PyObject *)pc;
          } else {
              PyEntity * pe = newPyEntity();
              if (pe == NULL) {
                  return NULL;
              }
              pe->m_entity.e = entity;
              wrapper = (PyObject *)pe;
          }
        } else {
          PyEntity * pe = newPyLocatedEntity();
          if (pe == NULL) {
              return NULL;
          }
          pe->m_entity.l = le;
          wrapper = (PyObject *)pe;
        }
        if (le->script() == &noScript) {
            pw = new PythonWrapper(wrapper);
            le->setScript(pw);
        } else {
            log(WARNING, "Entity has script of unknown type");
        }
    } else {
        wrapper = pw->wrapper();
        assert(wrapper != NULL);
        Py_INCREF(wrapper);
    }
    return wrapper;
}
예제 #2
0
파일: Py_Task.cpp 프로젝트: 9cat/cyphesis
PyObject * wrapTask(Task * task)
{
    PyObject * wrapper;
    Task * ts = dynamic_cast<Task *>(task);
    PythonWrapper * pw;
    if (ts == 0 || ((pw = dynamic_cast<PythonWrapper *>(ts->script())) == 0)) {
        PyTask * pt = newPyTask();
        if (pt != NULL) {
            pt->m_task = task;
        }
        wrapper = (PyObject *)pt;
        // This wrapper cannot be stashed back int the task yet so
        // we don't have to do this next time.
    } else {
        wrapper = pw->wrapper();
        assert(wrapper != NULL);
        Py_INCREF(wrapper);
    }
    return wrapper;
}