Accessing fields and functions of a NMODL object in NMODL

NMODL and the Channel Builder.
hines
Site Admin
Posts: 1710
Joined: Wed May 18, 2005 3:32 pm

Re: Accessing fields and functions of a NMODL object in NMODL

Post by hines »

Declare nil as an objref and just do not allow it to reference anything.

Code: Select all

oc>objref nil
oc>print nil
NULLobject 
oc>
Is that true?
Not quite.
hoc_objgetarg(1) returns an Object** so it is typically called via
Object* o = *hoc_objgetarg(1);
Then, if you want to be safe, check that the Object is a reference to a NetCon with
check_obj_type(o, "NetCon");
And then finally extract the pointer to the c++ NetCon object
void* vnc = o->u.this_pointer;
vnc can be the first arg to nrn_netcon_event
mctavish
Posts: 74
Joined: Tue Mar 14, 2006 6:10 pm
Location: New Haven, CT

Re: Accessing fields and functions of a NMODL object in NMODL

Post by mctavish »

Thanks for the help, Michael. I think I'm close.

In my hoc file I have

Code: Select all

objref A, B, nc, nil
A=new MyArtCell()
B=new MyArtCell()
nc=new NetCon(nil,B)
A.setNC(nc)
In my mod file I have

Code: Select all

ASSIGNED {
    netcon
}

PROCEDURE setNC() {
VERBATIM {
    if (ifarg(1)) {  // nc object passed in from hoc
        Object *o = *hoc_objgetarg(1);
        check_obj_type(o, "NetCon");
        void** nc_handle;
        nc_handle = (void**)(&netcon);
        *nc_handle = o->u.this_pointer;
    }
}
ENDVERBATIM
}

VERBATIM
extern void nrn_netcon_event(void* netcon_pointer, double tdeliver);
ENDVERBATIM

NET_RECEIVE(w) {
VERBATIM {
    nrn_netcon_event(*(void **)(&netcon), t+del);
}
ENDVERBATIM
}
To which I'm still getting a "NULLobject target is missing" error. I'm pretty sure that I'm not capturing and storing the netcon variable properly, but I don't know what the proper solution is.

Thanks,
Tom
mctavish
Posts: 74
Joined: Tue Mar 14, 2006 6:10 pm
Location: New Haven, CT

Re: Accessing fields and functions of a NMODL object in NMODL

Post by mctavish »

Well, I've got it. The previously-mentioned code did not have a problem, but my full-blown version did. I was reusing the nc variable in my hoc code, so I was pulling the rug out from the reference in my artificial cell. I'm now storing each nc in a List. Thanks for your help.
Post Reply