Skip to content

Commit b44291b

Browse files
authored
api-updates (#3411)
* Implemented reusable function to register func/object (e.g., used by both nrnmatlab and FInitializehandler for MATLAB session) * Function to get pval for NEURON functionality in Matlab (ref, get_prop) -> needed to get and set Neuron properties * Changed nrn_symbol_table_iterator_next's return value to Symbol* to avoid unnecessary name->symbol lookups * Fixed: add missing semicolon in header file * Removed nrn_pp_property_array_set (outdated function, included in nrn_property_array_set)
1 parent 5dd737c commit b44291b

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

src/nrniv/neuronapi.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct SectionListIterator {
2626

2727
struct SymbolTableIterator {
2828
explicit SymbolTableIterator(Symlist*);
29-
char const* next(void);
29+
Symbol* next(void);
3030
int done(void) const;
3131

3232
private:
@@ -196,6 +196,10 @@ int nrn_symbol_subtype(Symbol const* sym) {
196196
return sym->subtype;
197197
}
198198

199+
double* nrn_symbol_dataptr(Symbol* sym) {
200+
return sym->u.pval;
201+
}
202+
199203
void nrn_symbol_push(Symbol* sym) {
200204
hoc_pushpx(sym->u.pval);
201205
}
@@ -355,8 +359,8 @@ int SectionListIterator::done(void) const {
355359
SymbolTableIterator::SymbolTableIterator(Symlist* list)
356360
: current(list->first) {}
357361

358-
char const* SymbolTableIterator::next(void) {
359-
auto result = current->name;
362+
Symbol* SymbolTableIterator::next(void) {
363+
Symbol* result = current;
360364
current = current->next;
361365
return result;
362366
}
@@ -394,7 +398,7 @@ void nrn_symbol_table_iterator_free(SymbolTableIterator* st) {
394398
delete st;
395399
}
396400

397-
char const* nrn_symbol_table_iterator_next(SymbolTableIterator* st) {
401+
Symbol* nrn_symbol_table_iterator_next(SymbolTableIterator* st) {
398402
return st->next();
399403
}
400404

@@ -464,11 +468,6 @@ void nrn_property_array_set(Object* obj, const char* name, int i, double value)
464468
}
465469
}
466470

467-
void nrn_pp_property_array_set(Object* pp, const char* name, int i, double value) {
468-
int index = hoc_table_lookup(name, pp->ctemplate->symtable)->u.rng.index;
469-
ob2pntproc_0(pp)->prop->param_legacy(index + i) = value;
470-
}
471-
472471
void nrn_property_push(Object* obj, const char* name) {
473472
auto sym = hoc_table_lookup(name, obj->ctemplate->symtable);
474473
if (!obj->ctemplate->is_point_) {
@@ -511,4 +510,13 @@ Symlist* nrn_global_symbol_table(void) {
511510
Symlist* nrn_top_level_symbol_table(void) {
512511
return hoc_top_level_symlist;
513512
}
513+
514+
// Function to register function/object in hoc
515+
void nrn_register_function(void (*proc)(), const char* func_name) {
516+
Symbol* sym;
517+
sym = hoc_install(func_name, FUNCTION, 0, &hoc_top_level_symlist);
518+
sym->u.u_proc->defn.pf = proc;
519+
sym->u.u_proc->nauto = 0;
520+
sym->u.u_proc->nobjauto = 0;
521+
}
514522
}

src/nrniv/neuronapi.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Symbol* nrn_symbol(const char* name);
6363
void nrn_symbol_push(Symbol* sym);
6464
int nrn_symbol_type(const Symbol* sym);
6565
int nrn_symbol_subtype(Symbol const* sym);
66+
double* nrn_symbol_dataptr(Symbol* sym);
6667
void nrn_double_push(double val);
6768
double nrn_double_pop(void);
6869
void nrn_double_ptr_push(double* addr);
@@ -96,7 +97,7 @@ Section* nrn_sectionlist_iterator_next(SectionListIterator* sl);
9697
int nrn_sectionlist_iterator_done(SectionListIterator* sl);
9798
SymbolTableIterator* nrn_symbol_table_iterator_new(Symlist* my_symbol_table);
9899
void nrn_symbol_table_iterator_free(SymbolTableIterator* st);
99-
char const* nrn_symbol_table_iterator_next(SymbolTableIterator* st);
100+
Symbol* nrn_symbol_table_iterator_next(SymbolTableIterator* st);
100101
int nrn_symbol_table_iterator_done(SymbolTableIterator* st);
101102
int nrn_vector_capacity(const Object* vec);
102103
double* nrn_vector_data(Object* vec);
@@ -110,6 +111,7 @@ char const* nrn_symbol_name(const Symbol* sym);
110111
Symlist* nrn_symbol_table(Symbol* sym);
111112
Symlist* nrn_global_symbol_table(void);
112113
Symlist* nrn_top_level_symbol_table(void);
114+
void nrn_register_function(void (*proc)(), const char* func_name);
113115
// TODO: need shapeplot information extraction
114116

115117
#ifdef __cplusplus

0 commit comments

Comments
 (0)