Javascript Shared

From Yate Documentation
Revision as of 12:05, 3 September 2024 by Marian (Talk | contribs)

Jump to: navigation, search

General

Shared variables object.
Shared variable lists are available in all scripts.
They are thread safe.
NOTE: Values are stored as plain strings

Create

Retrieve Yate global

var g = Engine.shared;
var g = new Engine.SharedVars("");

Create separate shared variables list

var g = new Engine.Shared("mylist");


Methods

  • get(name)

Retrieve a variable as string

Parameters:
name Required variable name

Return:
Value of the variable


  • set(name,str)

Set a variable.

Parameters:
name Required variable name
str Required variable value


  • create(name[,str])

Create a variable if does not exist.
Do nothing if valriable is present in list.

Parameters:
name Required variable name
str Optional variable value. Create with empty string if this parameter is not given


  • inc(name[,wrap])

Atomically increment a variable as unsigned integer

Parameters:
name Required variable name
wrap Optional value to wrap around at, zero, negative or non numeric disables

Return:
Value of the variable before increment, zero if it was not defined or not numeric


  • dec(name[,wrap])

Atomically decrement a variable as unsigned integer

Parameters:
name Required variable name
wrap Optional value to wrap around at, zero, negative or non numeric disables

Return:
Value of the variable after decrement, zero if it was not defined or not numeric


  • add(name,value,[,wrap])

Atomically add an unsigned integer value to a variable

Parameters:
name Required variable name
value Required value to add
wrap Optional value to wrap around at, zero, negative or non numeric disables

Return:
Value of the variable before addition, zero if it was not defined or not numeric


  • sub(name,value,[,wrap])

Atomically substract an unsigned integer value from a variable

Parameters:
name Required variable name
value Required value to substract
wrap Optional value to wrap around at, zero, negative or non numeric disables

Return:
Value of the variable after substraction, zero if it was not defined or not numeric


  • clear(name)

Clear (remove) a variable

Parameters:
name Required variable name


  • clearAll()

Clear (remove) all variables in list
Does nothing if the list is the global variables list


  • exists(name)

Check if a variable exists

Parameters:
name Required variable name

Return:
Boolean true if variable exists, false otherwise


  • getVars([params])

Retrieve list variables

Parameters:
params Optional object with desired behaviour

params properties:

  • js_props: Boolean. Return property values as Javascript native types. Default: true
  • autonum: Boolean. Try to convert variables to numeric/boolean. Default: false.
    Set it when needing to return numbers.
    Ignored if not returning Javascript native types
  • prefix: String. Optional prefix for variables. Retrieve only variables whose name starts with given prefix
  • skip_prefix: Boolean. Skip prefix when returned. Default: true
    Ignored if prefix is empty

Return:
Object with list variables as properties

Personal tools
Namespaces

Variants
Actions
Preface
Configuration
Administrators
Developers