Sidebar

Home



Expressions V4


Tutorials

How-To

Reference

  Lexical basics
  Type system
  Variables and assignment
  Operators
  Expression rules
  Control flow
  Functions
  Built-in functions
   None and NaN
   Arithmetic
   Algebra
   Logarithmic and Exponential
   Trigonometric
   Rounding and Centering
   Strings
   Output, Formatting, Clipboard, and Errors
   Dialog Functions
   Platform and Paths
  Methods and properties
  Built-in methods
   Common Value Methods
   Number Methods
   String Basic Methods
   String Slice Methods
   String Parsing Methods
   String Formatting Methods
   String Regex Methods
   String Trim and Case Methods
  Objects
  Built-in objects
   Global objects
    settings
    controller
    session
    python
   Collections
    array
    map
    bytes
   File Format I/O
    image_data
    image_stream
   Utils
    crypto
    timer
   Comm
    serial
   Dialogs
    file_open
    file_save
    msg_ok
    msg_ok_cancel
    msg_yes_no
    msg_password
   GUI objects
    window
    panel
    group
    splitpanel
    label
    textbutton
    drawablebutton
    togglebutton
    togglegroup
    textinput
    textedit
    numinput
    slider
    combobox
    listbox
    progressbar
    led
    separator
    menu
    image
    snake
  Classes and user-defined objects
  Include system
  Error model
  Execution model and sessions
  Host integration
  Limits and performance
  Formal reference
  Glossary

Cookbook

exprv4:reference:objects:session

session

`session` is a built-in global object for inspecting and managing Expr sessions.

It is used directly by name. Do not call `session()`.

A session stores root variables, user-defined functions, user-defined classes, and the last result for a named evaluation context.

Constructor

`session` is a predefined global object. It is not created with a constructor.

Item Description
Syntax `session`
Arguments not applicable
Returns session object
print(session.current);

Properties

Properties are read-only. Use session methods to change session state.

Property Type Description
`current` string Name of the active session. The fallback session uses an empty name.
print(session.current);

Common Object Methods

to_string()

Returns a display string for the object.

Item Description
Syntax `value.to_string()`
Arguments none
Returns string

Example:

text = value.to_string();

`clone()` is not supported for `session`.

Methods

list()

Returns session names separated by new lines.

Item Description
Syntax `session.list()`
Arguments none
Returns string
print(session.list());

list_variables()

Returns variables in the current session, one per line.

Each line contains the variable name and value text.

Item Description
Syntax `session.list_variables()`
Arguments none
Returns string
print(session.list_variables());

list_functions_builtin()

Returns built-in function names, one per line.

Item Description
Syntax `session.list_functions_builtin()`
Arguments none
Returns string
print(session.list_functions_builtin());

list_classes_builtin()

Returns built-in object constructor names, one per line.

Item Description
Syntax `session.list_classes_builtin()`
Arguments none
Returns string
print(session.list_classes_builtin());

list_functions()

Returns user-defined function names in the current session, one per line.

Item Description
Syntax `session.list_functions()`
Arguments none
Returns string
print(session.list_functions());

list_classes()

Returns user-defined class names in the current session, one per line.

Item Description
Syntax `session.list_classes()`
Arguments none
Returns string
print(session.list_classes());

create(name)

Creates a new session named `name`.

`create()` does not switch the current context. Use `join(name)` to start using the new session.

If the session already exists, an error result is returned.

Item Description
Syntax `session.create(name)`
Arguments `name`: session name
Returns OK or error result
session.create('job1');
print(session.current);      // unchanged
 
session.join('job1');
print(session.current);      // job1

delete(name)

Deletes the session named `name`.

`delete()` does not switch the current context. Deleting the active session returns an error result. The fallback empty-name session cannot be deleted.

Join another session, or join the fallback session with session.join(''), before deleting a session that was active.

Item Description
Syntax `session.delete(name)`
Arguments `name`: session name
Returns OK or error result
old = session.current;
job = 'old_job';
 
session.create(job);
session.set_variable(job, 'old_session', old);
session.join(job);
 
// use job session here
 
session.join(old_session);
session.delete(job);

join(name)

Switches the current context to an existing session.

If the session does not exist, an error is raised. Passing an empty string joins the fallback empty-name session.

Item Description
Syntax `session.join(name)`
Arguments `name`: session name, or empty string for the fallback session
Returns OK result
session.join('job1');
 
session.join('');            // fallback empty-name session

clear()

Clears variables, user-defined functions, and user-defined classes from the current session.

Built-in global objects are restored after the clear operation.

Item Description
Syntax `session.clear()`
Arguments none
Returns OK result
session.clear();

has_variable(sessionName, variableName)

Returns `true` if `sessionName` contains `variableName`.

Use an empty `sessionName` to check the fallback session. If the named session does not exist, an error is raised.

Item Description
Syntax `session.has_variable(sessionName, variableName)`
Arguments `sessionName`: session name; `variableName`: variable name
Returns boolean
exists = session.has_variable('job1', 'part_count');

get_variable(sessionName, variableName)

Returns a variable from another session.

Use an empty `sessionName` to read from the fallback session. If the session or variable does not exist, an error is raised.

Object values must be cloneable. Non-cloneable object values cannot be copied between sessions.

Item Description
Syntax `session.get_variable(sessionName, variableName)`
Arguments `sessionName`: session name; `variableName`: variable name
Returns variable value
count = session.get_variable('job1', 'part_count');

set_variable(sessionName, variableName, value)

Sets a root variable in another session.

Use an empty `sessionName` to write to the fallback session. Passing `none()` removes the variable.

Object values must be cloneable. Non-cloneable object values cannot be copied between sessions.

Protected built-in global names such as `state`, `settings`, `gcode`, `controller`, `session`, and `python` cannot be overwritten.

Item Description
Syntax `session.set_variable(sessionName, variableName, value)`
Arguments `sessionName`: session name; `variableName`: variable name; `value`: value to store, or `none()` to remove
Returns OK result
old = session.current;
job = 'probe_job_001';
 
session.create(job);
session.set_variable(job, 'old_session', old);
session.join(job);
 
result = 17;
 
session.set_variable(old_session, 'result', result);
session.join(old_session);
session.delete(job);

Assignment

`session` is a protected built-in global name. The name itself cannot be overwritten.

session = 1;      // error

Use `session` methods to create, join, delete, clear, and inspect sessions.

Example

old = session.current;
job = 'probe_job_001';
 
session.create(job);
session.set_variable(job, 'old_session', old);
session.join(job);
 
safe_z = 5;
feed = 100;
result = safe_z + feed;
 
session.set_variable(old_session, 'probe_result', result);
session.join(old_session);
session.delete(job);
 
print(probe_result);

Previous: controller

Next: python

exprv4/reference/objects/session.txt · Last modified: by 127.0.0.1

Page Tools