Your Digital Media Has Never Looked So Good

 
User avatar
OG_OTT
Topic Author
Posts: 20
Joined: Mon Jul 30, 2018 3:52 pm

Introspect Roku Objects?

Mon Aug 06, 2018 10:42 pm

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!
 
User avatar
squirreltown
Posts: 836
Joined: Sun Apr 21, 2013 2:20 pm

Re: Introspect Roku Objects?

Tue Aug 07, 2018 9:23 am

Not sure if it's what you want but Brightscript has FormatJSON()  which is good for printing/peeking at arrays.
Kinetics Screensavers
 
User avatar
Komag
Posts: 748
Joined: Fri Aug 22, 2014 3:42 am

Re: Introspect Roku Objects?

Tue Aug 07, 2018 12:26 pm

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.
 
User avatar
OG_OTT
Topic Author
Posts: 20
Joined: Mon Jul 30, 2018 3:52 pm

Re: Introspect Roku Objects?

Wed Aug 08, 2018 4:49 pm

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://sdkdocs.roku.com/display/sdkdoc/Animation
  • Which lists members as:  `duration` `easeFunction` `easeInPercent` `easeOutPercent` and `optional`.  
  • Animation inherits(extends) from AnimationBase, which has `control` `state` `repeat` and `delay`.
  • And AnimationBase inherits(extends) from Node, which has.... hopefully you get the point.

What I am asking is can I do something like (again, pseudo coding this 'cause I don't know the syntax) but `dir(AnimationBase)` to get a listing of all of the members (methods/functions,fields/properties) that that object has available?  Sometimes the documentation leaves one asking questions, and having the ability to interrogate "classes" to see what's available sometimes yields powerful results.  

As an example, in a lot of other that I am familiar with languages (e.g. C#, CPP, Python, JavaScript) I can set a breakpoint (which I know I can do in RSG), and I can inspect an instance of an object to see all of it's methods/properties (e.g. 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!
 
User avatar
RokuKC
Posts: 305
Joined: Wed Sep 10, 2014 10:44 am
Location: Roku HQ

Re: Introspect Roku Objects?

Wed Aug 08, 2018 6:29 pm

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[k], &h200) : end for

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

Hope that helps.
 
User avatar
OG_OTT
Topic Author
Posts: 20
Joined: Mon Jul 30, 2018 3:52 pm

Re: Introspect Roku Objects?

Wed Aug 08, 2018 9:50 pm

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!
 
User avatar
Komag
Posts: 748
Joined: Fri Aug 22, 2014 3:42 am

Re: Introspect Roku Objects?

Thu Aug 09, 2018 7:35 am

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.
 
User avatar
squirreltown
Posts: 836
Joined: Sun Apr 21, 2013 2:20 pm

Re: Introspect Roku Objects?

Thu Aug 09, 2018 10:19 am

"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
 
User avatar
OG_OTT
Topic Author
Posts: 20
Joined: Mon Jul 30, 2018 3:52 pm

Re: Introspect Roku Objects?

Thu Aug 09, 2018 3:39 pm

Gotcha.  Thank you everyone.  I think I understand now.

Who is online

Users browsing this forum: No registered users and 3 guests