Skip to main content
Version: 7.0

Eval (EVAL)

The eval operator creates an action that, at runtime, compiles a string of lsFusion source code and executes it inside the running server, with full visibility of the rest of the project.

Source code

The string is treated as the body of a fresh module generated by the platform. The platform fills in the header automatically: a unique module name plus dependencies on every currently loaded module. The body can therefore reference any element of the project, and may itself declare new local elements.

Two source-code shapes are accepted, depending on the operator's mode:

  • Statements mode (default). The string is a sequence of statements. One of those statements must create an action named run; this is the action that gets executed. As a regular scripted action, run may declare interface parameters and pull values from them.
  • Action mode. The string is the body of an action — a sequence of action operators and local property declarations — wrapped by the platform into a run action automatically. The body addresses the eval action's runtime arguments positionally.

Parameters

The eval action accepts the source code as its first parameter. Additional argument values supplied to the operator become the runtime arguments passed to run when it is invoked, and they follow the usual parameter-passing rules.

Execution scope

The compiled run action runs synchronously in the calling action's session, so its reads and writes share the caller's session, apply, and transactional state.

Restrictions on the executable code

The executable code is meant to add new local elements and call existing ones; it cannot change the project's persistent structure. The following cannot appear in eval code:

  • declarations of new classes, tables, and indexes
  • global events and constraints, including the write-event and follows-constraint forms attached to a property declaration
  • aggregations, and the aggregation and equality modes of grouping
  • materialization, explicit table placement, and not-null constraints on properties
  • declaring a group with a parent group from another module, or attaching a property or action to a group from another module
  • adding base events to existing actions

Data properties declared inside eval code are forced to the session scope; persistent data declarations are not allowed.

Language

To create the eval action, use the EVAL operator.

Examples

// inline action body
addProperty { EVAL ACTION 'MESSAGE \'Hello World\''; }

// arbitrary script entered by the user
code 'Source code' = DATA BPSTRING[2000] ();
execute 'Execute code' { EVAL code(); }

// passing a runtime argument to the executed body in action mode
greet 'Greet user' (CustomUser u) { EVAL ACTION 'MESSAGE \'Hello, \' + name($1);' PARAMS u; }