The following is New Script translated to En:
When compiled, the LSL preprocessor will import all library functions and macros, then generate the entire default state based on defined preprocessor options.
En scripts are organized as follows:
Options are set using preprocessor #define directives. There are several types of options:
Feature options are options that are enabled when defined, regardless of value:
These flags cause En to add code to support a specific feature, and/or change the operation of an existing feature. For example, if FEATURE_ENRPC_PROTOCOL_CLEP is defined, En adds code for sending and receiving CLEP messages, as well as a self-contained listen event handler in the default state.
Event options are like feature options, but also cause En to call the option's name in lowercase as a function to report the corresponding LSL event:
These flags are required because the LSL preprocessor cannot detect if you have defined en_state_entry as a function. They cause En to pass a specific LSL-generated event through to a script-defined function of the same name, but lowercase. For example, if EVENT_EN_TOUCH_START is defined, En will create a touch_start event handler and immediately call en_touch_start when an event is received.
En manages all events because some En libraries need to intercept them. For example, enRPC can optionally create handlers and intercept http_request, http_response, link_message, and listen events; in that case, only messages that enRPC cannot handle are sent to their respective en_*() functions, assuming their respective EVENT_EN_* event flags are defined.
Overrides are options that have a default value, but can be overridden by being defined in the script:
In the above example, this forces enLog to send all logs more critical than TRACE via OwnerSay with debugging headers; this is a quick way to temporarily enable logging in an individual script during development.
While you can add comments to flags, do not add comments to overrides. All text after the override name will be injected into the script. This will cause the comment to be injected in-line and will break the script.
All En libraries must be included after overrides. This can be done with the following line:
If you use any other preprocessor libraries, include them after En.
Script-defined functions (both En passthroughs/callbacks and general user-defined functions) must be placed after including the libraries. Note that event options cannot be placed with their associated functions, because the preprocessor needs to know which are defined when including the libraries, but the libraries also need to be defined before any En constants (like TRACE) can be used.
Since it is impossible to determine the active state without custom code, En scripts typically only have the default state, in which the generic event handlers are included:
While state switching is useful in highly limited circumstances, it is generally not recommended in lieu of a global for En scripts unless absolutely necessary, since all states must have the same event handlers anyway.
En contains the following components:
The event-handlers directory contains indivdual .lsl files for each event in LSL.
En only imports an event handler if it is required by an invoked En library or the EVENT_EN_EVENT_NAME preprocessor flag, which triggers the associated en_event_name(...) function defined in the script. For example, the New Script in En passes through the state_entry and touch_start events.
All event handlers can also automatically log events via enLog_TraceParams if TRACE_EVENT_EVENT_NAME is defined. For example, by adding the following line to the En New Script:
Clicking the prim will log something similar to the following via OwnerSay if the enLog loglevel has been set to TRACE:
[20:47:15.61] (28% d0fb @214) New Script
🚦 touch_start(
num = 1
)
Then, En will call en_touch_start(...) and, by extension, llSay.
The libraries directory contains subdirectories for each library that contains a function.lsl and macros.lsl file for each. The macros.lsl files for all libraries are loaded first, then all function.lsl files are loaded, to allow libraries to cross-reference each others' macros.
Like event handlers, En only imports the functions defined by libraries if they are called, assuming you have set up your preprocessor correctly.
Some libraries can log function calls via enLog_TraceParams if TRACE_FUNCTION_NAME is defined.
The utilities directory contains full LSL scripts that perform certain utility functions. For example, enRPC_Tap.lsl can be used to monitor all RPC traffic in a prim: