#include "mess.h" typedef struct { fts_object_t o; /* MUST BE FIRST STRUCTURE MEMBER */ long n; /* the state of a integer object */ } integer_t; /* -------------------- the integer object methods -------------------- */ static void integer_init( fts_object_t *o, int winlet, fts_symbol_t *s, int ac, const fts_atom_t *at) { integer_t *this = (integer_t *)o; this->n = fts_get_long_arg(at, ac, 1, 0); } static void integer_bang( fts_object_t *o, int winlet, fts_symbol_t *s, int ac, const fts_atom_t *at) { integer_t *this = (integer_t *)o; fts_atom_t a; fts_set_long( &a, this->n); fts_outlet_send( o, 0, fts_s_int, 1, &a); } static void integer_int( fts_object_t *o, int winlet, fts_symbol_t *s, int ac, const fts_atom_t *at) { integer_t *this = (integer_t *)o; fts_atom_t a; this->n = fts_get_long_arg( at, ac, 0, 0); fts_set_long( &a, this->n); fts_outlet_send( o, 0, fts_s_int, 1, &a); } static void integer_float( fts_object_t *o, int winlet, fts_symbol_t *s, int ac, const fts_atom_t *at) { integer_t *this = (integer_t *)o; fts_atom_t a; this->n = (long)fts_get_float_arg(at, ac, 0, 0); fts_set_long( &a, this->n); fts_outlet_send( o, 0, fts_s_int, 1, &a); } static void integer_in1( fts_object_t *o, int winlet, fts_symbol_t *s, int ac, const fts_atom_t *at) { integer_t *this = (integer_t *)o; this->n = fts_get_long_arg(at, ac, 0, 0); } static void integer_float1( fts_object_t *o, int winlet, fts_symbol_t *s, int ac, const fts_atom_t *at) { integer_t *this = (integer_t *)o; this->n = (long)fts_get_float_arg(at, ac, 0, 0); } /* -------------------- the integer object instantiation function -------------------- */ static fts_status_t integer_instantiate(fts_class_t *cl, int ac, const fts_atom_t *at) { fts_atom_type_t a[2]; /* initialize the class */ fts_class_init( cl, sizeof(integer_t), 2, 1, 0); /* define the methods */ a[0] = fts_Symbol; a[1] = fts_Long|fts_OptArg; fts_method_define( cl, fts_SystemInlet, fts_s_init, integer_init, 2, a); a[0] = fts_Long; fts_method_define( cl, 0, fts_s_int, integer_int, 1, a); a[0] = fts_Float; fts_method_define( cl, 0, fts_s_float, integer_float, 1, a); fts_method_define( cl, 0, fts_s_bang, integer_bang, 0, 0 ); a[0] = fts_Long; fts_method_define( cl, 1, fts_s_int, integer_in1, 1, a ); a[0] = fts_Float; fts_method_define( cl, 1, fts_s_float, integer_float1, 1, a ); /* define outlet type */ a[0] = fts_Long; fts_outlet_type_define( cl, 0, fts_s_int, 1, a ); return fts_Success; } /* -------------------- the class installation function -------------------- */ void void integer_config(void) { /* create the class 'integer' */ fts_metaclass_create(fts_new_symbol("int"),integer_instantiate, fts_always_equiv); /* ... and register 2 aliases for the "int" name: "i" and "integer" */ fts_metaclass_alias(fts_new_symbol("integer"), fts_new_symbol("int")); fts_metaclass_alias(fts_new_symbol("i"), fts_new_symbol("int")); }