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: 
OG_OTT
Visitor

Introspect Roku Objects?

Is there a way to introspect objects in Roku?  For instance, if I `stop` in my brs file, and do a "? objectICareAbout" and it gives a bunch of fields/properties/attributes (what-have-you) but then shows "...", is there a way to do something like:

(using pseudo code)

for attribute in dir(objectICareAbout):
    print attribute



so I can see all of the members on that object?  My aim is that I am discovering that not everything is documented/published, and being able to interrogate the object (or use a form of reflection maybe?) would be pretty cool to kinda explore and poke around myself (dangerous, yes, but a great learning tool).

Does Roku RSG have ANY facilities close to this?  (I didn't see anything in Google or SDK documentation about this functionality - kinda hard to search for IMO).

Thanks!
0 Kudos
8 REPLIES 8
squirreltown
Roku Guru

Re: Introspect Roku Objects?

Not sure if it's what you want but Brightscript has FormatJSON()  which is good for printing/peeking at arrays.
Kinetics Screensavers
0 Kudos
Komag
Roku Guru

Re: Introspect Roku Objects?

You can type in a FOR loop but it needs to be all on one line, using : when needed, and it's a bit touchy if you try to combine any IF THEN type stuff in the middle.
0 Kudos
OG_OTT
Visitor

Re: Introspect Roku Objects?

Thank you SquirrelTown and Komag.

I think I either misunderstand your answers or I didn't ask the right questions.  I'll try reasking in a different way to see if it changes your response...


  • The SDK lists Animations as https://docs.python.org/2/library/functions.html#dir).  If I do this in RSG (e.g. "? <objectName?"), sometimes I get some helpful hints about the object (mostly things that I've defined), but then it [...] on me because it won't output to stdout that much information.

    I think the response about "for-looping" will get around the [...] but if I wanted to see all the supported methods/functions, and fields/properties of an object is there anything I can type at the debug/telnet to get that information?  It's not critical, but it's often a way I learn a new language/platform.

    Thanks again for helping me out!
0 Kudos
RokuKC
Roku Employee
Roku Employee

Re: Introspect Roku Objects?

"OG_OTT" wrote:
Is there a way to introspect objects in Roku?  For instance, if I `stop` in my brs file, and do a "? objectICareAbout" and it gives a bunch of fields/properties/attributes (what-have-you) but then shows "...",
...


? currently limits the object dump output to 100 lines, but we can look at changing that.
I spot-checked a few RSG node types and didn't see it running into this limit.
Was there a particular node type that you couldn't inspect this way?

You could also try:
for each k in yournode.keys() : print k; "="; formatjson(z, &h200) : end for

Or for more info:
for each k in yournode.keys() : print k; "="; z : end for

Hope that helps.
0 Kudos
OG_OTT
Visitor

Re: Introspect Roku Objects?

Thanks RokuKC.

For example I did:  


Brightscript Debugger> ?m  

<Component: roAssociativeArray> =[/size]
{
port: <Component: roMessagePort>[/size]
}

Brightscript Debugger> ?m.port.keys()[/size]
Member function not found in BrightScript Component or interface. (runtime error &hf4) in $LIVECOMPILE(29)



I was hoping to get the following output...
https://sdkdocs.roku.com/display/sdkdoc/ifMessagePort
Brightscript Debugger> a = {"a" : "1", "b" : "2" }

Brightscript Debugger> ?a
<Component: roAssociativeArray> =
{
    a: "1"
    b: "2"
}

Brightscript Debugger> ?a.keys()
<Component: roArray> =
[
    "a"
    "b"
]

**Where a and b are replaced with members for roMessagePort such as "WaitMessage" and "GetMessage" and "PeekMessage" and maybe any other members/attributes/properties/fields/methods/functions.


I really appreciate everyone being so patient with me while I ask the same question over and over again.  I want to be clear that I asked the question expecting a "no, that's available in RSG", and I understand the way I am asking is either confusing or just plain inaccurate, but again, I very much appreciate everyone's kindness while I stumble through this post.

Here is an example in python that I would normally do:

>>> dir(dict)
['__class__', '__cmp__', '__contains__', '__delattr__', '__delitem__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__',
'__init__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__',
'__str__', '__subclasshook__', 'clear', 'copy', 'fromkeys', 'get', 'has_key', 'items', 'iteritems', 'iterkeys', 'itervalues', 'keys', 'pop', 'popitem', 'setdefault',
'update', 'values', 'viewitems', 'viewkeys', 'viewvalues']


Above is Python - and dict is a common builtin.  Without reading the Python docs I can see exactly what is available to the dict() builtin.  From there I can get 'fancy' and do helps on help(dict.viewitems) and get information at either runtime or an interactive terminal.  
TOTALLY UNDERSTAND PYTHON != RSG =P.  I'm just asking if RSG has any way to expose the same information of an object/method/class/scenegraph/node.  
Thank you a 1000x over!
0 Kudos
Komag
Roku Guru

Re: Introspect Roku Objects?

I just keep a tab open to the reference docs, such as:
https://sdkdocs.roku.com/display/sdkdoc/ifAudioPlayer
I am quite often checking and referencing things here, mostly components and interfaces, but also the BrightScript Language Reference sometimes.
0 Kudos
squirreltown
Roku Guru

Re: Introspect Roku Objects?

"Where a and b are replaced with members for roMessagePort such as "WaitMessage" and "GetMessage" and "PeekMessage" and maybe any other members/attributes/properties/fields/methods/functions."

roMessagePort is a built in component, not just any old array. You don't get to see everything about it, just like roScreen and all the others. The things that are exposed to you are listed in the IfMessageport docs.
Kinetics Screensavers
0 Kudos
OG_OTT
Visitor

Re: Introspect Roku Objects?

Gotcha.  Thank you everyone.  I think I understand now.
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.