Max 5 API Reference

Symbols
[Data Types]

Max maintains a symbol table of all strings to speed lookup for message passing. More...

Collaboration diagram for Symbols:

Data Structures

struct  t_symbol
 The symbol. More...

Functions

t_symbolgensym (char *s)
 Given a C-string, fetch the matching t_symbol pointer from the symbol table, generating the symbol if neccessary.

Detailed Description

Max maintains a symbol table of all strings to speed lookup for message passing.

If you want to access the bang symbol for example, you’ll have to use the expression gensym("bang"). For example, gensym() may be needed when sending messages directly to other Max objects such as with object_method() and outlet_anything(). These functions expect a t_symbol*, they don’t gensym() character strings for you.

The t_symbol data structure also contains a place to store an arbitrary value. The following example shows how you can use this feature to use symbols to share values among two different external object classes. (Objects of the same class can use the code resource’s global variable space to share data.) The idea is that the s_thing field of a t_symbol can be set to some value, and gensym() will return a reference to the Symbol. Thus, the two classes just have to agree about the character string to be used. Alternatively, each could be passed a t_symbol that will be used to share data.

Storing a value:

    t_symbol *s; 
    s = gensym("some_weird_string"); 
    s->s_thing = (t_object *)someValue; 

Retrieving a value:

    t_symbol *s; 
    s = gensym("some_weird_string"); 
    someValue = s->s_thing; 

Function Documentation

t_symbol* gensym ( char *  s  ) 

Given a C-string, fetch the matching t_symbol pointer from the symbol table, generating the symbol if neccessary.

Parameters:
s A C-string to be looked up in Max’s symbol table.
Returns:
A pointer to the t_symbol in the symbol table.

Copyright © 2008, Cycling '74