messnamed equivalent 'send' function in C (send to named object)
Hi Max-devs,
A student of ours is getting into external programming and he was surprised to find out that there is no equivalent documented way to send values to a named object, as there is in javascript with 'messnamed'. He want's to send values to receive objects.
I went digging and indeed, I couldn't find anything official. All the subscription, binding etc. mechanisms are for objects, whose structure and binding we control ourselves. With the send/receive internals, however, these mechanisms won't work.
I put together a hack that gets me as far as the object pointers of the receive objects, but I'm missing the magic incantation to make the receiver understand what we are sending it (see attached).
Birds do it, bees do it, even simple javascripts do it, let's do it, let's send from C.
thanks for any information regarding this
/*j
//void * typedMessOutput = typedmess(o, gensym("anything"), 0, 0L);
// this doesn't work, since we don't know the message name
t_max_err err = object_notify(o, gensym("notify"), buf);
// this doesn't work either
Hi.
If I remember correctly, all send's and receive's with the same name reference a single nobox object called "through", which you can simply retrieving by looking at the s_thing field of the name symbol — I mean, if you need to retrieve the through object associated to the "foo" symbol, just look for gensym("foo")->s_thing.
Once you have the object, just send it a message with object_method().
Or, it might not be exactly like this but something along these lines...
I hope this helps,
aa
Thanks Andrea, that's it.
cheers
/*j
t_object *o = gensym("destination")->s_thing; // get [through] object from t_symbol
object_method(o, gensym("bang"));
Hi there,
what Andrea says is indeed correct.
Here it is in code with some necessary error checking:
t_max_err object_send_method_typed(void *x, t_symbol *name, t_symbol *s, long ac, t_atom *av, t_atom *rv)
{
t_object *thing = name->s_thing;
if (!thing) {
return MAX_ERR_INVALID_PTR;
}
if (NOGOOD(thing)) {
return MAX_ERR_INVALID_PTR;
}
if (!object_classname_compare(thing, gensym("through"))) {
return MAX_ERR_GENERIC;
}
return object_method_typed(thing, s, ac, av, rv);
}
Cheers
- Luigi
thanks luigi,
that looks to be the clean way!
all best
/*j
Hi guys,
I wonder if there is something wrong with this forum page... why can't I see Luigi's post?? I'd love to see the clean way, as opposed to my hacky one ;)
Cheers,
aa
I don't know what happened - here it is:
"Here it is in code with some necessary error checking:
t_max_err object_send_method_typed(void *x, t_symbol *name, t_symbol *s, long ac, t_atom *av, t_atom *rv)
{
t_object *thing = name->s_thing;
if (!thing) {
return MAX_ERR_INVALID_PTR;
}
if (NOGOOD(thing)) {
return MAX_ERR_INVALID_PTR;
}
if (!object_classname_compare(thing, gensym("through"))) {
return MAX_ERR_GENERIC;
}
return object_method_typed(thing, s, ac, av, rv);
}
Cheers
- Luigi"
Value objects do also have a hidden [through] object. I can find the named value but neither set nor get the [value]'s value with the object_method_typed call? ALso object_setvalueof / object_getvalueof doesn't work.