Max 5 API Reference

Extending expr
[Miscellaneous]

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   ex_cont.v_int
 shortcut for accessing members of an Ex_ex struct's ex_cont union.
#define ex_flt   ex_cont.v_flt
 shortcut for accessing members of an Ex_ex struct's ex_cont union.
#define ex_op   ex_cont.op
 shortcut for accessing members of an Ex_ex struct's ex_cont union.
#define ex_ptr   ex_cont.ptr
 shortcut for accessing members of an Ex_ex struct's ex_cont union.

Enumerations

enum  e_max_expr_types {
  ET_INT = 0x1,
  ET_FLT = 0x2,
  ET_OP = 0x3,
  ET_STR = 0x4,
  ET_TBL = 0x5,
  ET_FUNC = 0x6,
  ET_SYM = 0x7,
  ET_VSYM = 0x8,
  ET_LP = 0x9,
  ET_LB = 0x10,
  ET_II = 0x11,
  ET_FI = 0x12,
  ET_SI = 0x13
}
 

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:
x The expr object to evaluate.
argc Count of arguments in argv.
argv Array of nine Atoms that will be substituted for variable arguments (such as $i1) in the expression. Unused arguments should be of type A_NOTHING.
result A 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:
argc Count of arguments in argv.
argv Arguments that are used to create the expr. See the example below for details.
types A 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

Copyright © 2008, Cycling '74