// porres 2023
#include "m_pd.h"
static t_class *var_class;
typedef struct _var{
t_object x_obj;
t_int x_n; // number of given vars as arguments
t_symbol **x_sym; // variable names
}t_var;
static void var_bang(t_var *x){
t_atom at[x->x_n];
for(int i = 0; i < x->x_n; i++){
t_float f;
int flag = value_getfloat(x->x_sym[i], &f);
SETFLOAT(at+i, !flag ? f : 0);
}
outlet_list(x->x_obj.ob_outlet, &s_list, x->x_n, at);
}
static void var_list(t_var *x, t_symbol *s, int ac, t_atom *av){
s = NULL;
if(!ac)
var_bang(x);
else for(int i = 0; i < (ac > x->x_n ? x->x_n : ac); i++)
value_setfloat(x->x_sym[i], atom_getfloat(av+i));
}
static void var_free(t_var *x){
for(int i = 0; i < x->x_n; i++)
value_release(x->x_sym[i]);
freebytes(x->x_sym, x->x_n * sizeof(*x->x_sym));
}
static void *var_new(t_symbol *s, int ac, t_atom *av){
s = NULL;
t_var *x = (t_var *)pd_new(var_class);
x->x_sym = getbytes(sizeof(t_symbol) * (x->x_n = (!ac ? 1 : ac)));
if(!ac)
value_get(x->x_sym[0] = &s_);
else for(int i = 0; i < x->x_n; i++)
value_get(x->x_sym[i] = atom_getsymbol(av+i));
outlet_new(&x->x_obj, &s_list);
return(x);
}
void var_setup(void){
var_class = class_new(gensym("var"), (t_newmethod)var_new,
(t_method)var_free, sizeof(t_var), 0, A_GIMME, 0);
class_addbang(var_class, var_bang);
class_addlist(var_class, var_list);
}
Em seg., 9 de out. de 2023 às 20:27, Alexandre Torres Porres <porres@gmail.com> escreveu:but printing and debugging, it does say and show it was in fact created...here's to illustrate, I load the patch with a single [var a b c] object, and I'm printing at creation time that it's creating 'a', 'b' and 'c' which didn't exist before. If I duplicate the object, it says it's creating 'a' again as if it didn't already exist.. copy again and you get yet the same thing. Now if I delete the first object it shows that error where it couldn't find the variable to free it, as it really never existed. If I do "control z" and recreated the object, it recreates yet once again variable 'a'...I don't know how to test any further and it really seems there's NOTHING wrong with it with the code :)thanks