IfUtils

Available since Roku OS 15.0

Implemented by

NameDescription
roUtilsThe roUtils component provides a unique namespace for a library of global functions, including the DeepCopy() function for copying objects and their nested objects and the isSameObject() function for checking whether two BrightScript objects refer to the same instance.

Supported Methods

DeepCopy(data as Object) as Object

Description

Performs a deep copy of a node object (it copies the object and all of its nested objects). If the object contains items that are not copyable, they are skipped.

Parameters

NameTypeDescription
dataObjectThe object to be copied

Return Value

This function returns a copy of the specified object.

Example

utils = CreateObject("roUtils")
    di = CreateObject("roDeviceInfo")
    aa = { a: 1, b: { b1: 42 }, c: di }
    new_aa = utils.DeepCopy(aa)
    print "IsSameObject", utils.IsSameObject(aa, new_aa)
    print "new_aa.a", new_aa.a
    print "new_aa.b", new_aa.b
    print "new_aa.c", new_aa.c ' invalid, roDeviceInfo is not copyable

This code will output the following on the port 8085 console:

IsSameObject    false
new_aa.a         1
new_aa.b        <Component: roAssociativeArray> =
{
    b1: 42
}
new_aa.c        invalid

IsSameObject(data1 as Object, data2 as Object) as Boolean

Description

Checks whether two BrightScript objects refer to the same instance and returns a flag indicating the result.

Parameters

NameTypeDescription
data1ObjectFirst object
data2ObjectSecond object

Return Value

Returns true if data1 and data2 reference the same object; otherwise, this returns false.

Example

shared = {}
    aa = {"a": shared, "b": shared}
    utils = CreateObject("roUtils")
    utils.isSameObject(aa, aa)   ' returns true
    utils.isSameObject(aa, {})   ' returns false
    utils.isSameObject(aa.a, aa.b)  ' returns true

HasComponent(componentName as String) as Boolean

Available since Roku OS 15.2

Description

Verifies whether a component name is already registered. Developers can call this method before trying to create an instance.

Parameters

NameTypeDescription
componentNameStringThe component name to check for an existing registration.

Return Value

A flag indicating whether the specified component name has already been registered.

isNumber(val as Number) as Boolean

Available since Roku OS 15.3

Description

Verifies whether the provided value is any numeric type (int, float, double, long integer; boxed or unboxed).

Parameters

NameTypeDescription
valNumberThe value to be evlauated.

Return Value

A flag indicating whether the specified value is an Integer, LongInteger, Float, or Double.

Example

utils = CreateObject("roUtils")
? utils.IsNumber(invalid)              ' false
? utils.IsNumber(42)                   ' true
? utils.IsNumber(box(42))              ' true
? utils.IsNumber("42")                 ' false

isInteger(val as Integer) as Boolean

Available since Roku OS 15.3

Description

Verifies whether the provided value is an Integer or LongInteger (boxed or unboxed).

Parameters

NameTypeDescription
valIntegerThe value to be evlauated.

Return Value

A flag indicating whether the specified value is an Integer or LongInteger.

Example

utils = CreateObject("roUtils")
? utils.isInteger(42)               ' true
? utils.isInteger(box(42))         ' true
? utils.isInteger(invalid)          ' false

isFloatingPoint(val as Float) as Boolean

Available since Roku OS 15.3

Description

Verifies whether the provided value is a Float or Double (boxed or unboxed).

Parameters

NameTypeDescription
valFloatThe value to be evlauated.

Return Value

A flag indicating whether the specified value is a Float or a Double.

Example

utils = CreateObject("roUtils")
? utils.IsFloatingPoint(box(3.14)) ' true

isString(val as String) as Boolean

Available since Roku OS 15.3

Description

Verifies whether the provided argument is a string type (intrinsic or roString, boxed or unboxed).

Parameters

NameTypeDescription
valStringThe value to be evlauated.

Return Value

A flag indicating whether the specified value is a string type.

Example

utils = CreateObject("roUtils")
? utils.isString("foo")            ' true
? utils.isString(box("foo"))       ' true

Did this page help you?