[PD-dev] getting the classname in an class
Hans-Christoph Steiner
hans at eds.org
Mon Oct 29 19:48:43 CET 2007
I think this should be part of the standard save mechanism, so I just
committed the change to a bunch of externals. I didn't touch
externals/iem since I know you guys like to handle stuff yourself.
It actually makes sense like this (from entry.c):
static void entry_save(t_gobj *z, t_binbuf *b)
{
t_entry *x = (t_entry *)z;
binbuf_addv(b, "ssiisiiss", gensym("#X"),gensym("obj"),
x->x_obj.te_xpix, x->x_obj.te_ypix,
atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)),
x->x_width, x->x_height, x->x_bgcolour, x-
>x_fgcolour);
binbuf_addv(b, ";");
}
Perhaps atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)) could be
defined in m_pd.h as something like "class_getclassname"
.hc
On Oct 29, 2007, at 2:12 PM, IOhannes m zmoelnig wrote:
> Hans-Christoph Steiner wrote:
>> We have a winner! :D
>
> darn, i just finished an example that works as well....
>
>
> fmasdr.
> IOhannes
>
> /******************************************************
> *
> * myname - implementation file
> *
> * copyleft (c) IOhannes m zm-bölnig-A
> *
> * 2007:forum::f-bür::umläute:2007-A
> *
> * institute of electronic music and acoustics (iem)
> *
> ******************************************************
> *
> * license: GNU General Public License v.2
> *
> ******************************************************/
>
>
> /*
> * this object is an example on how to retrieve the object's own name
> * usage:
> * + bang to print the object's name to the console
> */
>
> #include "m_pd.h"
>
> /* ------------------------- myname ---------------------------- */
>
> static t_class *myname_class;
>
> typedef struct _myname
> {
> t_object x_obj;
> } t_myname;
>
> static void myname_bang(t_myname *x) {
> t_text t=(t_text)x->x_obj;
> t_binbuf*b=t.te_binbuf;
> if(b!=0) {
> t_atom*ap=binbuf_getvec(b);
> post("my name is '%s'", atom_getsymbol(ap)->s_name);
> } else {
> post("hmm, i don't know my name");
> }
> }
>
>
> static void *myname_new(void)
> {
> t_myname *x = (t_myname *)pd_new(myname_class);
>
> t_text t=(t_text)x->x_obj;
> t_binbuf*b=t.te_binbuf;
> if(b!=0) {
> t_atom*ap=binbuf_getvec(b);
> post("my name is '%s'", atom_getsymbol(ap)->s_name);
> } else {
> post("i don't know my name yet...");
> }
>
> return (x);
> }
>
> void myname_setup(void)
> {
> myname_class = class_new(gensym("myname"), (t_newmethod)myname_new,
> 0, sizeof(t_myname), 0, 0);
> class_addbang(myname_class, myname_bang);
> }
------------------------------------------------------------------------
----
Terrorism is not an enemy. It cannot be defeated. It's a tactic.
It's about as sensible to say we declare war on night attacks and
expect we're going to win that war. We're not going to win the war
on terrorism. - retired U.S. Army general, William Odom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puredata.info/pipermail/pd-dev/attachments/20071029/97f6fdfc/attachment.htm>
More information about the Pd-dev
mailing list