Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

ON THIS PAGE


The intrinsic types Int32, Float, and string have object and interface equivalents. These are useful in the following situations:

  • An object is needed instead of a typed value.  For example, roList maintains a list of objects.
  • If any object exposes the ifInt, ifFloat, or ifString interfaces, that object can be used in any expression that expects a typed value. For example, an roTouchEvent can be used as an integer whose value is the userid of the roTouchEvent.

 

If "o" is of type roInt, then these statements will have the following effects:

  • print o: Prints the value of o.GetInt()
  • i%=o: Assigns the integer i% the value of o.GetInt().
  • k=o: Presumably k is automatically typed, so it becomes another reference to the roInt  o.
  • o=5: This is NOT the same as o.SetInt(5). Instead it releases o, changes the type of o to roINT32 (o is automatically typed), and assigns it to 5.

When a function that expects a BrightScript object as a parameter is passed an int, float, or string, BrightScript automatically creates the equivalent object.

ifInt

roInt contains the ifInt interface, which provides the following:

GetInt() As Integer
SetInt(value As Integer) As Void

ifIntOps

roInt also contains the ifIntOps interface, which provides the following:

ToStr() As String

ifFloat

roFloat contains the ifFloat interface, which provides the following:

GetFloat() As Float
SetFloat(value As Float) As Void

ifString

roString contains the ifString interface, which provides the following:

GetString() As String
SetString(value As String) As Void

ifStringOps

roString also contains the ifStringOps interface, which provides the following:

Note

The function indexes of ifStringOps methods start at zero, while the function indexes of global methods start at one.

SetString(str As String, str_len As Integer)

Sets the string using the specified string and string-length values.

AppendString(str As String, str_len As Integer)

Appends the string using the specified string and string-length values. This method modifies itself—this can cause unexpected results when you pass an intrinsic string type, rather than a string object.

Example
x="string"
x.ifstringops.appendstring("ddd",3)
print x 'will print 'string' 
y=box("string")
y.ifstringops.appendstring("ddd",3)
print y 'will print 'stringddd'
Len() As Integer
GetEntityEncode() As String
Tokenize(delim As String) As Object
Trim() As String
ToInt() As Integer
ToFloat() As Float
Left(chars As Integer) As String
Right(chars As Integer) As String
Mid(start_index As Integer) As String
Mid(start_index As Integer, chars As Integer) As String
Instr(substring As String) As Integer
Instr(start_index As Integer, substring As String) As Integer

 


 

Example
BrightScript> o=CreateObject("roInt")
BrightScript> o.SetInt(555)
BrightScript> print o
555
BrightScript> print o.GetInt()
555
BrightScript> print o-55
500 

 

An integer value of 5 is converted to type roInt automatically because the AddTail() method expects a BrightScript object as its parameter:

Example
BrightScript> list=CreateObject("roList")
BrightScript> list.AddTail(5)
BrightScript> print type(list.GetTail()) 


Here the ListDir() method returns an roList object containing roString objects:

Example
BrightScript> l=ListDir("/")
BrightScript> for i=1 to l.Count():print l.RemoveHead():next
test_movie_3.vob
test_movie_4.vob
test_movie_1.vob
test_movie_2.vob
  • No labels