Wrapper objects and intrinsic type promotion – BrightSign BrightScript 2 Reference Guide User Manual
Page 15

15
The for-each statement works on any object that has an “ifEnum” interface. These
include: Array, Associative Array, List, and Message Port.
Print
The print #object, “hello” format will print “into” any object that has an “ifStreamSend”
interface. These include the TextField and SerialPort objects.
If the expression being printed evaluates to an object that has an “ifEnum” interface, print
will print every item that can be enumerated.
In addition to printing the values of intrinsic types, “print” will also print any object that
exposes one of these interfaces: ifString, ifInt, ifFloat..
Wait
The wait function will work on any object that has an “ifMessagePort” interface.
Array Operator –“[]”
The array operator works on any object that has an “ifArray” or “ifAssociativeArray”
interface. This includes Array, Associative Array, and Lists.
Member access operator “.”
The “.” Operator works on any object that has an “ifAssociativeArray” interface (as well
as on any Roku Object (when calling a member function)). It also has special meaning
when used on roXMLElement or roXMLList.
Expression Parsing
Any expression that is expecting an Integer, Float, Double, Boolean or String, can take an
object with the “ifInt”, “ifFloat”, “ifBoolean” or “ifString” interface.
Wrapper Objects and intrinsic type promotion
The intrinsic BrightScript types integer, float, double, string, invalid, boolean and
function all have object equivalents. If one of these intrinsic types is passed to a function
that expects an Object, the appropriate wrapper object will be created, assigned the
correct value, and passed to the function. This is sometimes referred to as “autoboxing”.
This is how, for example, roArray can store integers and strings as well as objects.
Any expression that expects one of the above types will work with the corresponding
wrapper object as well.
For example:
Dim array[10]
Array.push(5)
intobj = array.pop()
print intobj+2
„ prints 7
print intobj.GetInt()+2
„ prints 7
print type(intobj)
„ prints “roInt”