IfUtils
Available since Roku OS 15.0
Implemented by
| Name | Description |
|---|---|
| roUtils | The 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
| Name | Type | Description |
|---|---|---|
| data | Object | The 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 copyableThis 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 invalidIsSameObject(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
| Name | Type | Description |
|---|---|---|
| data1 | Object | First object |
| data2 | Object | Second 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 trueHasComponent(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
| Name | Type | Description |
|---|---|---|
| componentName | String | The 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
| Name | Type | Description |
|---|---|---|
| val | Number | The 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") ' falseisInteger(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
| Name | Type | Description |
|---|---|---|
| val | Integer | The 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) ' falseisFloatingPoint(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
| Name | Type | Description |
|---|---|---|
| val | Float | The 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)) ' trueisString(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
| Name | Type | Description |
|---|---|---|
| val | String | The 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")) ' trueUpdated about 5 hours ago
