EXPRESSION()

From Lianjapedia
Jump to: navigation, search

PURPOSE

Evaluate a Lianja expression

SYNONYM

LIANJA_EVALUATE()

SYNOPSIS

#include "lianja_api.h"
 
int	LIANJA_EVALUATE(result, exp)
 
<input parameters>
char	*exp;			/* Address of a buffer containing a valid Lianja expression */
 
<output parameters>
API_EXPRESSION result;		/* Expression result	*/

DESCRIPTION

The LIANJA_EVALUATE() function evaluates the specified Lianja expression and returns the result. This function returns 0 if successful, otherwise an error number.

The API Expression result structure is defined as follows:

struct API_EXPRESSION{
    int			errnum;		/* error() number		*/
    char		type;		/* data type of result		*/
    int			width;		/* width of result		*/
    int			decimal;	/* decimal places		*/
    char		*character;	/* CHARACTER result		*/
    double		number;		/* NUMERIC result		*/
    char		logical;	/* LOGICAL result		*/
    DATE	        date;		/* DATE result			*/
    DATETIME		datetime;	/* DATETIME result		*/
    CURRENCY	        currency;	/* CURRENCY result		*/
};

The data type result will be any one of the following:

RETURN VALUE DESCRIPTION
C character or memo data type
N numeric data type
D date data type
L logical data type
T datetime data type
Y currency data type

EXAMPLE

The following example evaluates the specified expression and returns the result.

Example Lianja script:

use accounts
m_result=evaluate("ord_value - paid_value")
return

Example 'C' function:

#include "lianja_api.h"
 
lianjaapi_evaluate()
{
	struct	API_EXPRESSION result;
 
	if (_parinfo(1) == API_CTYPE) {
		LIANJA_EVALUATE(&result, _parc(1));
 
		if (result.errno != 0) {
			_retni(-1);
		} else {
			_retnd(result.number);
		}
	} else {
		_retni(-1);
	}
}

SEE ALSO

COMMAND()