Javascript Shared

From Yate Documentation
(Difference between revisions)
Jump to: navigation, search
(Methods)
(Methods)
 
(One intermediate revision by one user not shown)
Line 34: Line 34:
 
'''name''' Required variable name<br/>
 
'''name''' Required variable name<br/>
 
'''str''' Required variable value<br/>
 
'''str''' Required variable value<br/>
 +
  
 
* '''create(name[,str])'''
 
* '''create(name[,str])'''
Line 42: Line 43:
 
'''name''' Required variable name<br/>
 
'''name''' Required variable name<br/>
 
'''str''' Optional variable value. Create with empty string if this parameter is not given<br/>
 
'''str''' Optional variable value. Create with empty string if this parameter is not given<br/>
 +
  
 
* '''inc(name[,wrap])'''
 
* '''inc(name[,wrap])'''
Line 119: Line 121:
 
'''params''' properties:
 
'''params''' properties:
 
* '''js_props''': Boolean. Return property values as Javascript native types. Default: true
 
* '''js_props''': Boolean. Return property values as Javascript native types. Default: true
* '''autonum''': Boolean. Try to convert variables to numeric/boolean. Default: false.<br/>Set it when needing to return numbers.<br/>Ignored if not returning Javascript native types
+
* '''autonum''': Boolean. Try to convert variables to numeric. Default: false.<br/>Set it when needing to return numbers.<br/>Ignored if not returning Javascript native types
 +
* '''autobool''': Boolean. Try to convert variables to boolean. Default: false.<br/>Set it when needing to return boolean values.<br/>Ignored if not returning Javascript native types
 
* '''prefix''': String. Optional prefix for variables. Retrieve only variables whose name starts with given prefix
 
* '''prefix''': String. Optional prefix for variables. Retrieve only variables whose name starts with given prefix
 
* '''skip_prefix''': Boolean. Skip prefix when returned. Default: true<br/>Ignored if prefix is empty
 
* '''skip_prefix''': Boolean. Skip prefix when returned. Default: true<br/>Ignored if prefix is empty

Latest revision as of 12:08, 3 September 2024

[edit] General

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

[edit] Create

Retrieve Yate global

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

Create separate shared variables list

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


[edit] 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. Default: false.
    Set it when needing to return numbers.
    Ignored if not returning Javascript native types
  • autobool: Boolean. Try to convert variables to boolean. Default: false.
    Set it when needing to return boolean values.
    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