Name
Eval -- evaluate string expression (V5.0)
Synopsis
val = Eval(expr$[, table])
Function
Eval() evaluates the numeric expression passed to it in expr$ and returns its result as a number. The string passed in expr$ can use all operators that are recognized by Hollywood except the string concatenation operator because this operator requires a string while the Eval() function only works with numbers. You can also prioritize certain subexpressions by using parentheses. The operators defined by Eval() use the same priorities as in Hollywood itself. See Operator priorities for a list of all Hollywood operators and their priorities.

Numbers inside expr$ can be specified in decimal or hexadecimal format. If you use hexadecimal format, you have to prefix the number using the $ dollar sign.

It is also possible to use variables in the expression. Your script variables, however, are not automatically available to Eval(). To make your script variables available to Eval(), you need to set the MapVariables tag in the optional table argument to True. Alternatively, you can also choose to define private variables for Eval() by setting the Variables tag in the optional table argument. If both script variables and private variables are used, the private ones will take precedence.

Here is a list of all tags currently supported by the optional table argument:

Variables:
This tag can be used to pass an array of variables that you want your expression to be able to access to Eval(). You have to pass an array here that consists of a number of Name and Value pairs. Name must contain the desired name for the variable and Value must contain the value the variable should be initialized to. The semantics of the variable name are the same as in Hollywood, i.e. it is only allowed to use alphanumerical characters plus the special characters "$", "!", and "_". The first character must not be a number. See below for an example.

MapVariables:
If this tag is set to True, Eval() will also take normal Hollywood variables into account when evaluating the expression. Note that the variables must be numeric variables only and the ones declared in the Variables tag (see above) will take precedence. Defaults to False. (V9.0)

NoDeclare:
If this tag is set to True, all undeclared variables in the expression will be treated as 0. By default, Eval() will throw an error when trying to access an undeclared variable. Defaults to False. (V9.0)

Inputs
expr$
numeric expression to evaluate
table
optional: table containing further arguments
Results
val
evaluation result
Example
v = Eval("5*(6+1)")
The call above returns 35.


v = Eval("var1*(var2+1)", {Variables = {{Name = "var1", Value = 5},
         {Name = "var2", Value = 6}}})
The code above does the same as the first example but uses variables instead of direct numbers.


var1 = 5
var2 = 6
v = Eval("var1*(var2+1)", {MapVariables = True})
The code above does the same as the first two examples but now maps the Hollywood variables var1 and var2 to Eval()'s variable space.

Show TOC