Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
EnTerr
Level 9

roXmlList implements ifArray, apparently (+ a mystery)

Just discovered that roXmlList supports ifArray methods:
BrightScript Debugger> rXL = createObject("roXmlList")
BrightScript Debugger> rXL.push("something")
BrightScript Debugger> ? type(rXL), rXL.count(), rXL[0]
roXMLList 1 something
BrightScript Debugger> ? getInterface(rXL, "ifArray")
<Interface: ifArray>

It is undocumented as of now. The significance is that array operations can be used to go over a roXmlList - and notably, .count().
0 Kudos
18 Replies
TheEndless
Level 7

Re: roXmlList implements ifArray, apparently

"EnTerr" wrote:
The significance is that array operations can be used to go over a roXmlList - and notably, .count().

.Count() is an ifList method.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
EnTerr
Level 9

Re: roXmlList implements ifArray, apparently

"TheEndless" wrote:
.Count() is an ifList method.

Hm, yeah - .count() is a method of both ifList and ifArray, good catch. But check this out - seems when you use count() on roXmlList, it's neither ifList's nor ifArray's:
BrightScript Debugger> ? rXL.count()
1
BrightScript Debugger> ? rXL.ifList.count()
0
BrightScript Debugger> ? rXL.ifArray.count()
0

Huuuh? :shock:
0 Kudos
belltown
Level 7

Re: roXmlList implements ifArray, apparently

"EnTerr" wrote:
"TheEndless" wrote:
.Count() is an ifList method.

Hm, yeah - .count() is a method of both ifList and ifArray, good catch. But check this out - seems when you use count() on roXmlList, it's neither ifList's nor ifArray's:
BrightScript Debugger> ? rXL.count()
1
BrightScript Debugger> ? rXL.ifList.count()
0
BrightScript Debugger> ? rXL.ifArray.count()
0

Huuuh? :shock:

From the BrightScript Language Reference:

specifying the interface with the dot operator is optional. If it is left out ,... , each interface in the object is searched for the member function. If there is a conflict (a member function with the same name appearing in two interfaces), then the interface should be specified.
https://github.com/belltown/
0 Kudos
EnTerr
Level 9

Re: roXmlList implements ifArray, apparently

"belltown" wrote:
From the BrightScript Language Reference:
specifying the interface with the dot operator is optional. If it is left out ,... , each interface in the object is searched for the member function. If there is a conflict (a member function with the same name appearing in two interfaces), then the interface should be specified.

Right, i knew that. That is what i showed, "explicifying" the interface to use.

But which .count() returns 1 if it isn't ifList's nor ifArray's? ifXmlList has no .count()...
0 Kudos
belltown
Level 7

Re: roXmlList implements ifArray, apparently (+ a mystery)

It's the mystery, undocumented Count().

Isn't it just a little annoying that the Roku docs don't tell the whole picture?

Speaking of undocumented features, I just found out a few minutes ago that roAudioPlayer supports live streaming AAC audio. For years, the documentation has been adamant that it only supports WMA and MP3.
https://github.com/belltown/
0 Kudos
Roku Employee
Roku Employee

Re: roXmlList implements ifArray, apparently

"EnTerr" wrote:

Hm, yeah - .count() is a method of both ifList and ifArray, good catch. But check this out - seems when you use count() on roXmlList, it's neither ifList's nor ifArray's:
BrightScript Debugger> ? rXL.count()
1
BrightScript Debugger> ? rXL.ifList.count()
0
BrightScript Debugger> ? rXL.ifArray.count()
0



This isn't calling rXL interface methods, but instead returning the list of its children with those names.

From the BrightScript Language Reference:

3.7.2 Dot Operator

The dot operator can be used on any BrightScript Component. It also has special meaning when used on any roAssociativeArray, roXMLElement or roXMLList.
...
See the section on XML support for details on using the dot operator on xml objects.


4.5 BrightScript XML Support
...
Dot Operator

1.When applied to an roXMLElement, the dot operator returns an roXMLList of children that match the dot operand. If no tags match, an empty list is returned.
2.When applied to an roXMLList, the dot operator aggregates the results of performing the dot operator on each roXMLElement in the list.
...


Example:

BrightScript Debugger> xml = CreateObject("roXMLElement")
BrightScript Debugger> xml.Parse("<a> <ifArray>1</ifArray> <ifList>b</ifList> <ifArray>2</ifArray> <ifArray>3</ifArray> </a>")
BrightScript Debugger> ? xml.ifArray.Count()
3
BrightScript Debugger> ? xml.ifList.Count()
1
0 Kudos
EnTerr
Level 9

Re: roXmlList implements ifArray, apparently

"RokuKC" wrote:
"EnTerr" wrote:

Hm, yeah - .count() is a method of both ifList and ifArray, good catch. But check this out - seems when you use count() on roXmlList, it's neither ifList's nor ifArray's:
BrightScript Debugger> ? rXL.count()
1
BrightScript Debugger> ? rXL.ifList.count()
0
BrightScript Debugger> ? rXL.ifArray.count()
0

This isn't calling rXL interface methods, but instead returning the list of its children with those names.

Oh wow, good catch!
Thank you, i assumed that dot-named interfaces always take precedence. To quote the relevant part of 3.7.2:
"3.7.2 Dot Operator" wrote:

...
When used on a BrightScript Component, it refers to an interface or a member function.
Example
i = CreateObject("roInt")
i.ifInt.SetInt(5)
i.SetInt(5)

"ifInt" is the interface, and "SetInt" is the member function. Every member function of a BrightScript Component is part of an interface. However, specifying the interface with the dot operator is optional. If it is left out, as in the last line of the example above, each interface in the object is searched for the member function. If there is a conflict (a member function with the same name appearing in two interfaces), then the interface should be specified.

Why is it that method resolution takes precedence over roXmlList-specific-dotting - but interface resolution does not? In other words, why "rXL.count()" works and "rXL.ifArray.count()" does not - when doco says both should work?

Because a component may implement 2 interfaces with overlapping method names (as the case is here - roXmlList implements both ifList and ifArray and both have .count()s ) - there should always be a way to "explicitate" which of the two methods i want, shouldn't it?!
0 Kudos
destruk
Level 10

Re: roXmlList implements ifArray, apparently (+ a mystery)

"belltown" wrote:
It's the mystery, undocumented Count().

Isn't it just a little annoying that the Roku docs don't tell the whole picture?

Speaking of undocumented features, I just found out a few minutes ago that roAudioPlayer supports live streaming AAC audio. For years, the documentation has been adamant that it only supports WMA and MP3.


" The component understands the following streamformat values: "mp3", "wma", "mp4", "hls", "es.aac-adts", "flac""
http://sdkdocs.roku.com/display/sdkdoc/roAudioPlayer

It's been updated
0 Kudos
belltown
Level 7

Re: roXmlList implements ifArray, apparently (+ a mystery)

"destruk" wrote:
"belltown" wrote:
It's the mystery, undocumented Count().

Isn't it just a little annoying that the Roku docs don't tell the whole picture?

Speaking of undocumented features, I just found out a few minutes ago that roAudioPlayer supports live streaming AAC audio. For years, the documentation has been adamant that it only supports WMA and MP3.


" The component understands the following streamformat values: "mp3", "wma", "mp4", "hls", "es.aac-adts", "flac""
http://sdkdocs.roku.com/display/sdkdoc/roAudioPlayer

It's been updated

Thanks. I just noticed that myself. AAC and FLAC don't seem to work on 3.1 fw though.
https://github.com/belltown/
0 Kudos