Max API  8.0.2
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...

Data Structures

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

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 (long argc, t_atom *argv, t_atom *types)
 Create a new expr object. More...
 
short expr_eval (t_expr *x, long argc, t_atom *argv, t_atom *result)
 Evaluate an expression in an expr object. More...
 

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

◆ e_max_expr_types

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

◆ expr_eval()

short expr_eval ( t_expr x,
long  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 t_atom values that will be substituted for variable arguments (such as $i1) in the expression. Unused arguments should be of type A_NOTHING.
resultA pre-existing t_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 t_atom values. 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.

◆ expr_new()

void* expr_new ( long  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 t_atom values, 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