Extending expr

If you want to use C-like variable expressions that are entered by a user of your object, you can use the "guts" of Max’s expr object in your object. More...

+ Collaboration diagram for Extending expr:

Data Structures

struct  Ex_ex
 ex_ex. More...
struct  t_expr
 Struct for an instance of expr. More...

Defines

#define ex_int
 shortcut for accessing members of an Ex_ex struct's ex_cont union.
#define ex_flt
 shortcut for accessing members of an Ex_ex struct's ex_cont union.
#define ex_op
 shortcut for accessing members of an Ex_ex struct's ex_cont union.
#define ex_ptr
 shortcut for accessing members of an Ex_ex struct's ex_cont union.

Enumerations

enum  e_max_expr_types {
  ET_INT, ET_FLT, ET_OP, ET_STR,
  ET_TBL, ET_FUNC, ET_SYM, ET_VSYM,
  ET_LP, ET_LB, ET_II, ET_FI,
  ET_SI
}
 Defines for ex_type. More...

Functions

void * expr_new (short argc, t_atom *argv, t_atom *types)
 Create a new expr object.
short expr_eval (t_expr *x, short argc, t_atom *argv, t_atom *result)
 Evaluate an expression in an expr object.

Detailed Description

If you want to use C-like variable expressions that are entered by a user of your object, you can use the "guts" of Max’s expr object in your object.

For example, the if object uses expr routines for evaluating a conditional expression, so it can decide whether to send the message after the words then or else. The following functions provide an interface to expr.


Enumeration Type Documentation

Defines for ex_type.

We treat parenthesis and brackets special to keep a pointer to their match in the content.

Enumerator:
ET_INT 

an int

ET_FLT 

a float

ET_OP 

operator

ET_STR 

string

ET_TBL 

a table, the content is a pointer

ET_FUNC 

a function

ET_SYM 

symbol ("string")

ET_VSYM 

variable symbol ("$s?")

ET_LP 

left parenthesis

ET_LB 

left bracket

ET_II 

and integer inlet

ET_FI 

float inlet

ET_SI 

string inlet


Function Documentation

short expr_eval ( t_expr x,
short  argc,
t_atom argv,
t_atom result 
)

Evaluate an expression in an expr object.

Parameters:
xThe expr object to evaluate.
argcCount of arguments in argv.
argvArray of nine Atoms that will be substituted for variable arguments (such as $i1) in the expression. Unused arguments should be of type A_NOTHING.
resultA pre-existing Atom that will hold the type and value of the result of evaluating the expression.
Returns:
.
Remarks:
Evaluates the expression in an expr object with arguments in argv and returns the type and value of the evaluated expression as a t_atom in result. result need only point to a single t_atom, but argv should contain at least argc Atoms. If, as in the example shown above under expr_new(), there are “gaps” between arguments, they should be filled in with t_atom of type A_NOTHING.
void* expr_new ( short  argc,
t_atom argv,
t_atom types 
)

Create a new expr object.

Parameters:
argcCount of arguments in argv.
argvArguments that are used to create the expr. See the example below for details.
typesA pre-existing array of nine t_atoms, that will hold the types of any variable arguments created in the expr. The types are returned in the a_type field of each t_atom. If an argument was not present, A_NOTHING is returned.
Returns:
expr_new() creates an expr object from the arguments in argv and returns the type of any expr-style arguments contained in argv (i.e. $i1, etc.) in atoms in an array pointed to by types.
Remarks:
types should already exist as an array of nine Atoms, all of which will be filled in by expr_new(). If an argument was not present, it will set to type A_NOTHING. For example, suppose argv pointed to the following atoms:
    $i1 (A_SYM) 
    + (A_SYM) 
    $f3 (A_SYM) 
    + (A_SYM) 
    3 (A_LONG) 

After calling expr_new, types would contain the following:

    Index   Argument    Type        Value 
    0   1 ($i1)     A_LONG      0 
    1   2       A_NOTHING   0 
    2   3 ($f3)     A_FLOAT     0.0 
    3   4       A_NOTHING   0 
    4   5       A_NOTHING   0 
    5   6       A_NOTHING   0 
    6   7       A_NOTHING   0 
    7   8       A_NOTHING   0 
    8   9       A_NOTHING   0