Can I access the text attribute of the box I'm in during my new routine

AlexHarker's icon

Hi,

I am writing an object that needs to internally host a patch with a single object in it. The internal object should receive exactly the text of the host object without any alteration. I have a method right now that works based on the translation of the atoms passed as A_GIMME back to a c-string, but this translation to-form stage seems unnecessary. I imagine that it theoretically could result in some minor changes in floating-point values.

The issue is that as my object hasn't yet been created and returned to the API I presume I have no way of getting it's box and then accessing the text attribute of the box (which is the C-string I want). I need it to be a C-string, because I need to call newobject_sprintf to create the internal object within a patch.

I include the top of the relevant routine below. The bit at the bottom shows how I currently grab the C-string from the atoms using atom_gettext. Any pointers to making this less clunky would be appreciated.

Thanks

Alex

void *wrapper_new(t_symbol *s, long argc, t_atom *argv)
{
    t_wrapper *x = (t_wrapper *)object_alloc(wrapper_class);
        
    t_dictionary *d = dictionary_new();
    t_atom a;
    t_atom *av = NULL;
    long ac = 0;
    
    atom_setparse(&ac, &av, "@defrect 0 0 300 300");
    attr_args_dictionary(d, ac, av);
    atom_setobj(&a, d);
    x->patch_internal = (t_object *)object_new_typed(CLASS_NOBOX,gensym("jpatcher"),1, &a);
        
    char name[256];
    sprintf(name, "unsynced.%s", OBJECT_NAME);
    
    char *text = NULL;
    long textsize = 0;
    
    atom_gettext(argc, argv, &textsize, &text, 0);
    x->obj_internal = jbox_get_object((t_object *) newobject_sprintf(x->patch_internal, "@maxclass newobj @text \"%s %s\" @patching_rect 0 0 30 10", name, text));

.... etc