[PD-dev] class_addmethod2

Mathieu Bouchard matju at artengine.ca
Sun Nov 20 19:57:24 CET 2005


A few days ago I added class_addmethod2 to m_class.c and m_pd.h.

Its advantages over class_addmethod are:

  1. it doesn't use varargs and you don't need to remember to use A_NULL
  2. the syntax is shorter so declarations can fit in one line
  3. it's closer to how binbuf_addv works

basically, atom types are given letters:

f=A_FLOAT   F=A_DEFFLOAT
s=A_SYMBOL  S=A_DEFSYMBOL
p=A_POINTER
*=A_GIMME
!=A_CANT  (e.g. for dsp messages)

so instead of writing:

  class_addmethod(myclass, (t_method)myclass_mymethod, gensym("mymethod"), 
    A_POINTER, A_FLOAT, A_FLOAT, A_SYMBOL, A_DEFFLOAT, A_DEFFLOAT, 
    A_DEFSYMBOL, A_NULL);

you can write:

  class_addmethod2(myclass, (t_method)myclass_mymethod, gensym("mymethod"), 
    "pffsFFS");

and class_addmethod3 is a macro in desire.c which further abbreviates it:

  class_addmethod3(myclass, myclass_mymethod, "mymethod", "pffsFFS");

____________________________________________________________________
Mathieu Bouchard - tél:+1.514.383.3801 - http://artengine.ca/matju
Freelance Digital Arts Engineer, Montréal QC Canada




More information about the Pd-dev mailing list