Changeset 14

Show
Ignore:
Timestamp:
04/24/07 17:48:56 (2 years ago)
Author:
hines
Message:

some connecting of the Python Section to the Python HocObject

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/pygetsetcall/src/nrnpython/nrnpy_hoc.cpp

    r13 r14  
    2222extern void hoc_call(); 
    2323extern Objectdata* hoc_top_level_data; 
     24extern void sec_access_push(); 
     25myPyMODINIT_FUNC nrnpy_nrn(); 
     26extern PyObject* nrnpy_cas(PyObject*, PyObject*); 
    2427/* 
    2528Because python types have so many methods, attempt to do all set and get 
     
    303306                        return sym->arayinfo; 
    304307                }else{ 
    305                         hoc_top_level_data[sym->u.oboff + 1].arayinfo; 
     308                        return hoc_top_level_data[sym->u.oboff + 1].arayinfo; 
    306309                } 
    307310        } 
     
    355358        hoc_objectvar(); 
    356359        hoc_pc = pcsav; 
     360} 
     361 
     362static PyObject* hocobj_getsec(Symbol* sym) { 
     363        Inst fc; 
     364        fc.sym = sym; 
     365        Inst* pcsav = save_pc(&fc); 
     366        sec_access_push(); 
     367        hoc_pc = pcsav; 
     368        PyObject* result = nrnpy_cas(0, 0); 
     369        nrn_popsec();                    
     370        return result; 
    357371} 
    358372 
     
    430444                        ((PyHocObject*)result)->type_ = 1; 
    431445                        hoc_obj_ref(((PyHocObject*)result)->ho_); 
     446                }else{ 
     447                        result = (PyObject*)intermediate(self, sym, -1); 
     448                } 
     449                break; 
     450        case SECTION: 
     451                if (!ISARRAY(sym)) { 
     452                        result = hocobj_getsec(sym); 
    432453                }else{ 
    433454                        result = (PyObject*)intermediate(self, sym, -1); 
     
    559580*/ 
    560581static PyObject* hocobj_getitem(PyObject* self, int ix) { 
    561 //printf("hocobj_getitem %d\n", i); 
    562582        PyObject* result = NULL; 
    563583        PyHocObject* po = (PyHocObject*)self; 
     
    589609                                ((PyHocObject*)result)->type_ = 1; 
    590610                                hoc_obj_ref(((PyHocObject*)result)->ho_); 
     611                                break; 
     612                        case SECTION: 
     613                                hocobj_pushtop(po, 0, ix); 
     614                                result = hocobj_getsec(po->sym_); 
    591615                                break; 
    592616                        } 
     
    635659                                err = 1; 
    636660                        } 
     661                        break; 
     662                default: 
     663                        PyErr_SetString(PyExc_TypeError, "not assignable"); 
    637664                        break; 
    638665                } 
     
    710737//printf("AddObject HocObject\n"); 
    711738        PyModule_AddObject(m, "HocObject", (PyObject*)hocobject_type); 
     739        nrnpy_nrn(); 
    712740} 
    713741 
  • branches/pygetsetcall/src/nrnpython/nrnpy_nrn.cpp

    r1 r14  
    632632}; 
    633633 
    634 static PyObject* cas(PyObject* self, PyObject* args) { 
     634PyObject* nrnpy_cas(PyObject* self, PyObject* args) { 
    635635        Section* sec = chk_access(); 
    636636        NPySecObj* pysec = NULL; 
     
    649649 
    650650static PyMethodDef nrnpy_methods[] = { 
    651         {"cas", cas, METH_VARARGS, "Return the currently accesses section." }, 
     651        {"cas", nrnpy_cas, METH_VARARGS, "Return the currently accesses section." }, 
    652652        {NULL} 
    653653};