Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
thanhpham
Visitor

Re: roInt & roInteger

? type([0][0]) = type(box(0))


In fact, this will print out "false".
The zero wrapped in an array has the type "roInteger" while the boxed zero has the type "roInt".
I am on firmware 7.5.
0 Kudos
Komag
Roku Guru

Re: roInt & roInteger

Here's what I use:

'======================== TYPE CHECKS =========================
' Apparently all of these are a lot faster than doing something like: IF Type(Th.spriteDraw) <> "roBoolean" ' or: IF Type(id) = "String" OR Type(id) = "roString"
' All these from The Endless: http://forums.roku.com/viewtopic.php?f=34&t=82858&view=unread#p476634
Function IsBoolean(value As Dynamic) As Boolean
    Return GetInterface(value, "ifBoolean") <> INVALID
End Function

Function IsString(value As Dynamic) As Boolean
    Return GetInterface(value, "ifString") <> INVALID
End Function

Function IsArray(value As Dynamic) As Boolean
    Return GetInterface(value, "ifArray") <> INVALID
End Function

Function IsAssociativeArray(value As Dynamic) As Boolean
    Return GetInterface(value, "ifAssociativeArray") <> INVALID
End Function

Function IsInteger(value As Dynamic) As Boolean
    Return GetInterface(value, "ifInt") <> INVALID And (Type(value) = "roInt" Or Type(value) = "roInteger" Or Type(value) = "Integer")
End Function

Function IsFloat(value As Dynamic) As Boolean
    Return (GetInterface(value, "ifFloat") <> INVALID Or (Type(value) = "roFloat" Or Type(value) = "Float"))
End Function

Function IsDouble(value As Dynamic) As Boolean
    Return (GetInterface(value, "ifDouble") <> INVALID Or (Type(value) = "roDouble" Or Type(value) = "roIntrinsicDouble" Or Type(value) = "Double"))
End Function

Function IsList(value As Dynamic) As Boolean
    Return GetInterface(value, "ifList") <> INVALID
End Function

Function IsDateTime(value As Dynamic) As Boolean
    Return (GetInterface(value, "ifDateTime") <> INVALID Or Type(value) = "roDateTime")
End Function

Function IsXmlElement(value As Dynamic) As Boolean
    Return GetInterface(value, "ifXMLElement") <> INVALID
End Function

Function IsFunction(value As Dynamic) As Boolean
    Return GetInterface(value, "ifFunction") <> INVALID
End Function

Function IsHttpAgent(value As Dynamic) As Boolean
    Return GetInterface(value, "ifHttpAgent") <> INVALID
End Function
0 Kudos
RokuNB
Roku Guru

Re: roInt & roInteger

"thanhpham" wrote:
? type([0][0]) = type(box(0))

In fact, this will print out "false".
The zero wrapped in an array has the type "roInteger" while the boxed zero has the type "roInt".
I am on firmware 7.5.

So it does, it's a bug or a feature.
Don't check for type() = string, instead check getInterface(x, "roInt") <> invalid - will work for all kind of ints.
Brightscript Debugger> for each i in [1, [1][0], box(1), 1.0]: ? i, type(i), type(i, 3), getInterface(i, "ifInt") <> invalid: next 
1 roInteger Integer true
1 roInteger Integer true
1 roInt roInt true
1 roFloat Float false
0 Kudos