Mathieu Bouchard wrote:
On Sat, 16 Dec 2006, Martin Peach wrote:
...so a string atom would have a_type = A_STRING and a_w = a_w.w_string, which points to a t_string containing the length and a pointer to the string.
If pd is otherwise able to handle atom types it doesn't know about (?),
It's not. There are no provisions for adding any extra atom types. There's no table for registering atom types. Out of 12 assigned numbers for atom types, 5 aren't actually atom types, 4 are radioactive types (SEMI,COMMA,DOLLAR,DOLLSYM), the remaining three have reserved selectors and hardcoded entries in t_class. What's the right way to add a fourth one like that?
As I see it the atom types are defined in m_pd.h and registered in m_class.c, which would need to have functions added to it to handle string, like adding: t_symbol s_symbol = {"string", 0, 0}; to the list of t_symbols around line 555, and changing: static t_symbol *symlist[] = { &s_pointer, &s_float, &s_symbol, &s_bang, &s_list, &s_anything, &s_signal, &s__N, &s__X, &s_x, &s_y, &s_}; to: static t_symbol *symlist[] = { &s_pointer, &s_float, &s_symbol, &s_bang, &s_list, &s_anything, &s_signal, &s__N, &s__X, &s_x, &s_y, &s_, &s_string}; ...and pd_typedmess would need a handler for string messages. No doubt the undergrowth gets more tangled the further in you get....
all the string manipulation objects could be built as externals.
What if strings could be automatically cast to symbols for externals that would rather have symbols, and vice-versa?
I have written an external asc2sym that takes lists of bytes and splits them into symbols based on the argument(s) which are characters. But it seems important to avoid symbols as much as possible to avoid filling up the symbol table with symbols that are referenced only once..
It looks too easy to me...
It's because you've only thought about the easy part of the problem. How do you know when a string becomes unused? When do you deallocate the memory? What does this mean for the API used by externals? (including the things that are assumed but not written in m_pd.h)
A string could be considered unused when its length is set to 0. Memory would need to be dynamically allocated in small blocks. The API should return "no method for string" if the external doesn't implement strings.
Martin