| |
OVM supports session variables. These are special string variables that continue to exist even after a script file has been closed (Ie. Their lifetime is for the session of Wozterm / Wozix). They have a different syntax to ordinary string variables and are indicated by the curly braces that appear around their names - eg {"fred"}. Note that session variables should not be confused with variable substitution which occurs only within implicit host command lines. The best use of session variables is when passing common data between scripts at runtime, and for building associative data structures such as dictionaries etc.
@set {"fred"} = "Hello World" ! Create a session variable called 'fred'A session variable must always contain a valid string expression between the {}. This can be a string literal, string variable name, or string expression. The value of this expression determines the name of the session variable. Note that unlike ordinary variable names session variable names can be up to 255 characters long and contain any ASCII character.
@set {"Mary and Fred"} = "A nice couple" ! Create a session variable called 'Mary and Fred'
The value of a session variable can be used where a string expression is also valid.
@comment("Mary and Fred = ",{"Mary and Fred"})A session variable’s value cannot be used in the place of a command. Although this type of variable substitution was Ozterm 6 it is not allowed in the OVM language. Attempting to use it as such will result in a syntax error at compile time.
! The following was allowed in Ozterm 6 but not in OVM @set fred = "prompt" ! Note - @prompt is a command @{fred} ! Ozterm 6 runs @prompt - Not allowed by OVM
The variable is created the first time the value of the variable is set, and you can use varexist to test if it has been created.
@if varexist("fred") then @comment("The value of fred = ",{"fred"}) @else @comment("fred does not exist") @set {"fred"} = "Hello there!" ! Create fred @if varexist("fred") then @comment("The value of fred = ",{"fred"}) @else @comment("fred does not exist")The name of the session variable is given by the evaluated contents of the {}.
@set {"fred"} = "Hello there" ! create fred and assign value "Hello there" @string mary = "jane" ! create mary and assign value "jane" @set {mary} = "Hi there" ! create jane and assign value "Hi there"Use the {} to retrieve the value of a session variable
@comment("fred") ! will display fred @comment({"fred"}) ! will display Hello There @comment(mary) ! will display jane @comment({mary}) ! will display Hi there
You can destroy session variables by using the flushvar, and flushall commands.
@if varexist("fred") then ! if session variable fred exists @flushvar("fred") ! then destroy it @flushall ! destroy all session variables
Because session variables exist until Wozterm and Wozix exit or when explicity destroyed with flushvar and flushall you can use session variables to pass information between files.
In file1.cmd
! Create 4 session variables called ! mode, destination, username, and password. ! Then pass control to file2.cmd to make use of them. @set {"mode"} = "NEM AXE" @set {"destination"} = "EDSA" @set {"username"} = "c123456" @set {"password"} = "mypassword" @run("file2.cmd")In file2.cmd
! Now use the session variables created by file1.cmd. @mode({"mode"}) @connect({"destination"},"",{"username"},{"password"})
In Ozterm 6 {} were required to allow the creation of arrays, and in many places to allow the contents of a variable to be accessed. In OVM most of these applications have been provided either by the normal behaviour of ordinary variables, or through the use of arrays of variables.
In Ozterm 6 the contents of {} had to be the name of a previously "defined" ordinary variable which led to term variable substitution. In OVM variable substitution is used only within implicit host commands.
Session variables do not have the same naming restrictions that ordinary variables have. The name of a session variable can include any character including ASCII 0, and can be up to 255 characters long.
! The following is an awful way to display Hello World @{"create a session variable with a really long name"} = "Hello World" @comment({"create a session variable with a really long name"})Each session variable uses at least 520 bytes of memory at runtime. 260 bytes of memory is reserved hold the name of the variable, and 260 bytes to hold the contents of the variable.
Session variables are slower to use at runtime than ordinary variables. This is because they are held in a runtime structure that must be searched for the variable’s name every time the variable is used. The addresses of ordinary variables are fixed at compile time, and hence are much quicker to access.
| |
| This publication has been prepared and written by Telstra Corporation Limited (ACN 051 775 556), and is copyright. Other than for the purposes of and subject to the conditions prescribed under the Copyright Act, no part of it may in any form or by any means (electronic, mechanical, microcopying, photocopying, recording or otherwise) be reproduced, stored in a retrieval system or transmitted without prior written permission from the document controller. Product or company names are trademarks or registered trademarks of their respective holders. Note for non-Telstra readers: The contents of this publication are subject to change without notice. All efforts have been made to ensure the accuracy of this publication. Notwithstanding, Telstra Corporation Limited does not assume responsibility for any errors nor for any consequences arising from any errors in this publication. |