Difference between revisions of "Extensible Object Script"
(→Examples) |
|||
Line 177: | Line 177: | ||
utilizing a Extensible Services / Server for Automation based system. | utilizing a Extensible Services / Server for Automation based system. | ||
− | <shl> | + | <shl class="mw-collapsible mw-collapsed"> |
/* | /* |
Revision as of 17:25, 27 December 2022
Extensible Object Script | |
---|---|
Developer | Texas Instruments, Netroda Technologies, A. Zeneli et. al. |
Type | Scripting Language |
Licenses | LGPL |
Initial release |
2002 |
Current Version | 2.10.2 |
Platform | EOSRuntime (Java / Platform Independent) |
Origin |
|
Paradigm | Imperative Procedural |
Typing | Dynamic, Weak |
Influences | Java, ActionScript, JavaScript |
Extensible Object Script (short "EOS") is the Scripting language used for Systems Based on the Extensible Services / Server for Automation family. Extensible Object Script features Object mixing, caching, lambda expressions and strict/weak typing.
Extensible Object Script runs inside the ES/S-A Enviroment (Java-Based) and is compatble with Java Objects (Objects extending java.lang.Object). As Java-based Language (Processed by JCC and Apache BCEL) it is theoretically plattform independent, as the runtime can be executed on any Java-capable platform.
Contents
Background
ExtensibleObjectScript is a general purpose object-oriented programming and scripting language. It is designed to be simple to learn, easy to use, yet still powerful, combining the convenience of a just-in-time interpreter with the features and reliability of the surrounding Java virtual machine. Its origins trace to ObjectScript developed originally by Texas Instrument until the early 2000s.
Introduction
Extensible Object Script is a full featured object oriented scripting language, which combines the powerful features of a full blown programming language such as Java with the ease of use of a scripting language. It supports functions (which can be closures), classes, inheritance, synchronization (for multi-threaded programs) and garbage collection. Also, an ObjectScript program can take advantage of exising Java APIs by creating instances of Java classes, calling methods of Java objects, and even implementing Java interfaces or extending Java classes. As the Core of Extensible Services / Server for Automation is java based, Extensible Object Script integrates seamlessly.
Uses
Scripts utilizing EOS are used to create Complex Typed System Assets (CTSA), Create and modify Area Service Controllers (ASXC) and to create user programs, like recurring tasks, automation routines and similar.
Examples
// A Simple While-Loop var a = 0; while(true) { a++; if( a > 5 ) break; else continue; a = 10; // this line is never evaluated }
// Two For-Loops var arr = []; for( var i=0; i<10; i++ ) arr[i] = i; var sum = 0; for( var item : arr ) sum += item;
// Simple Recursion function fib(n) { if( n == 0 ) throw new Exception("Invalid Input"); else if( n == 1 ) return 1; else if( n == 2 ) return 1; else return fib(n-1) + fib(n-2); }
// Objects and Object-Mixing function Color() { public function setRGB( r, g, b ) { // ... } } function Shape() { // ... } function Square() extends Shape() { public function setSize( w, h ) { // ... } } /* derived class created using mixins: */ function ColoredSquare() { mixin new Square(); mixin new Color(); } var coloredSquare = new ColoredSquare(); coloredSquare.setRGB( 0xff, 0xff, 0xff ); coloredSquare.setSize( 25, 50 );
A Example complex program shown below, this snippets creates a Lighting theme for a residential or public building utilizing a Extensible Services / Server for Automation based system.
/* Created on 09.01.2021 ALSC Setup - Extensible Object Script ---------------------------------------------------------------------------------------- The designated Area's Light Service Controller functions and allocations. ---------------------------------------------------------------------------------------- Copyright (C), N.P.A.L. 2015, 2021 Netroda Technologies, all rights reserved. this software can be reproduced, altered shared or distributed according to the terms of the Netroda Parity Access License (N.P.A.L.) See http://www.netroda.com/global/en/license/npal for further information Hint: to work with features and structures provided use the following variables provided */ var inp1 = ESS.Services.PTSA.getAssetById("ASES_0F26A000001"); // input1 => mode(on/off/auto) var highCeiling = ESS.Services.CTSA.getAssetById("CSES_0000P09F0E9A0"); // HIGH_CEILING_LAMP var dev2 = ESS.Services.CTSA.getAssetById("CSES_0000P09F0EA81"); var dev3 = ESS.Services.CTSA.getAssetById("CSES_0000P09F0EA82"); const var HIGH_CEILING_LAMP = 0; ALSC.primaryLights.createDevice(highCeiling,HIGH_CEILING_LAMP); // Reference Device 1 (high ceiling lamp) ALSC.primaryLights.createDevice(dev2,2); // Reference Device 2 ALSC.primaryLights.createDevice(dev3,3); // Reference Device 3 ALSC.primaryLights.addModeEventHandler( new (function() extends Lambda.ALSCModeEventHandler(){ var timer; public function onModeChange(e){ debug("Mode Changed"); timer = ESS.Runtime.invokeLater( new (function() extends EOSFoundation.ESSRunnable(){ public function run(){ debug("Mode Indication..."); debug(ESS.Services.DateTime.now()); var complexObject = ESS.Services.Complex.resolveArea("c0.b0.lv1.a001"); var currentMode = complexObject.lightsService.primaryLights.primaryMode.valueOf(); var modeIndicatorDevice = ESS.Services.PTSA.getAssetById("ASES_0FE00050001"); debug("Curr Mode (ext): " + currentMode); debug("Curr Mode (int): " + currentMode); if(currentMode == "ConstantOn"){ modeIndicatorDevice.inp(ContextAuthority,128); } else if(currentMode == "ConstantOff"){ modeIndicatorDevice.inp(ContextAuthority,0); } else if(currentMode == "Automatic"){ modeIndicatorDevice.inp(ContextAuthority,255); } } })(),0 ); } })() ); ALSC.primaryLights.createInput( inp1, new (function() extends EOSFoundation.InputEventHandler(){ public function onChange(e){ debug("Changed: Input 1"); } public function onHigh(e){ debug("High: Input 1, Cycling ALSC Mode..."); // this function is executed asynchronously in a new StackFrame, // so it might be necessary to reallocate the base ALSC object var complexObject = ESS.Services.Complex.resolveArea("c0.b0.lv1.a001"); complexObject.lightsService.primaryLights.cycleMode(); } public function onLow(e){ debug("Low: Input 1"); } })() ); ALSC.primaryLights.addTheme( new (function() extends Lambda.ALSCTheme(){ name = "Visitors"; allowModes = ["ConstantOn","ConstantOff","Automatic"]; public function onLoad(){ } public function onUnload(newTheme){ debug("Theme \""+name+"\" has been unloaded, new: " + newTheme); } public function onManualActivation(){ } public function onPresency(){ } public function onModeChange(modeArgument){ } public function onPanic() { } })() ); ALSC.primaryLights.addTheme( new (function() extends Lambda.ALSCTheme(){ name = "Cleaning Service"; allowModes = ["ConstantOn","ConstantOff"]; public function onLoad(){ //set the mode without invoking handlers [ changeMode(a,b) a=name b=silent ] because we just changed our theme //to prevent detrimental effects on the lost theme. var complexObject = ESS.Services.Complex.resolveArea("c0.b0.lv1.a001"); complexObject.lightsService.primaryLights.changeMode("ConstantOn",true); debug("Theme \""+name+"\" has been loaded"); evaluate(); } public function onUnload(newTheme){ debug("Theme \""+name+"\" has been unloaded, new: " + newTheme); //unload components if(highCeiling.isPoweredOn()){ highCeiling.requestPowerOffInstant(); } } public function onManualActivation(){ } public function onPresency(){ } public function onModeChange(modeArgument){ evaluate(); } public function onPanic(){ } private function evaluate(){ var complexObject = ESS.Services.Complex.resolveArea("c0.b0.lv1.a001"); var currentMode = complexObject.lightsService.primaryLights.primaryMode.valueOf(); if(currentMode == "ConstantOn"){ if(highCeiling.isPoweredOff()){ highCeiling.requestPowerOnInstant(); } } else if(currentMode == "ConstantOff"){ if(highCeiling.isPoweredOn()){ highCeiling.requestPowerOffInstant(); } } } })() );