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



Objects

Objects are Expr values that contain state and expose methods or properties.

Expr uses objects for collections, host integration, GUI controls, callbacks, and user-defined class instances.


Object Values

An object value is stored in a variable like any other value.

items = array(1, 2, 3);
lookup = map('x', 10);

Objects are usually used through methods.

items.add(4);
lookup.get('x');

Some objects also expose read-only properties.

lookup.x;

Property assignment is not supported. Use object methods to change object state.


Object Constructors

Built-in objects are usually created by built-in constructor functions.

items = array();
lookup = map();

User-defined objects are created by calling an Expr class constructor.

class Counter(start)
{
    value = start;
}
 
c = Counter(10);

Built-in constructor functions are listed in Built-in functions.


Object Methods

Object methods are called with dot syntax.

object.method(arguments);

The methods available depend on the object type.

Examples:

array(1, 2, 3).size();
map('x', 10).has('x');

General method call rules are described in Methods and properties.


Object Properties

Some objects expose properties that can be read with dot syntax.

object.property;

Property support is object-specific. If the property does not exist, Expr raises a runtime error.

Direct property assignment is not supported.

object.property = 10;     // not supported

Cloning and String Conversion

Some objects can be cloned with `clone()`.

a = array(1, 2, 3);
b = a.clone();

Objects also support `to_string()`.

array(1, 2, 3).to_string();
map('x', 10).to_string();

Whether `clone()` is supported depends on the object type.


Built-in and User-defined Objects

Built-in objects are implemented by Expr or the host application. See Built-in objects.

User-defined objects are created with Expr classes. See Classes and user-defined objects.

Previous: String Trim and Case Methods

Next: Built-in objects

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

Page Tools