introspection

29 views
Skip to first unread message

Jon Schull

unread,
May 14, 2018, 12:00:54 PM5/14/18
to Glowscript Users
In vpython I find it very useful to print or interrogate mybox.__dict__  and dir(mybox)  

In glowscript, such things don't work.  mybox is undefined (although mybox.pos and other attributes I have set are accessible...if I know what to ask for) 

Do you have any tips on introspection (or plans for making mybox not be undefined?)






Bruce Sherwood

unread,
May 14, 2018, 3:42:00 PM5/14/18
to Glowscript Users
I've never used these features of Python and am ignorant about them. I suggest that you create a class and see what these structures do with such a class. If they do something reasonable, what's missing is that the JavaScript "classes" in GlowScript need to add these features in order for them to work. If they don't do something reasonable, you would need to report it at https://github.com/kovidgoyal/rapydscript-ng.

Bruce

Jon Schull

unread,
May 14, 2018, 8:19:13 PM5/14/18
to glowscri...@googlegroups.com
Thanks for the suggestion.  It forced me to boil the problem down.  

As shown here, the embedded compiler half-believes that objects instantiated outside of the embedded compiler are "undefined".  

(That is if b=box(), b prints as undefined, but 
b.pos is nonetheless shown to be <0,0,0>)

FYI, __dict__ and dir() show the attributes and methods of the object





If the "Undefined Problem" gets solved, you might use __dict__ and __dir__ to craft a __repr__ method, which might could allow (e.g,) 
print(b) to display b's user-defined attributes and values. (as when one prints a dict, for example, in python). 
(__repr__ is illustrated in the other report as well)

Bruce Sherwood

unread,
May 14, 2018, 8:52:55 PM5/14/18
to Glowscript Users
I'm not sure whether it is relevant or not, but do read the section "External classes" in the README at the rapydscript-ng github repository.

Bruce

Jon Schull

unread,
May 15, 2018, 1:17:45 AM5/15/18
to glowscri...@googlegroups.com
Thanks

I had the same thought today. Will explore.

And thanks for today's advance!
On Mon, May 14, 2018 at 8:52 PM Bruce Sherwood <bruce.s...@gmail.com> wrote:
I'm not sure whether it is relevant or not, but do read the section "External classes" in the README at the rapydscript-ng github repository.

Bruce

--

---
You received this message because you are subscribed to the Google Groups "Glowscript Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to glowscript-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Founder,  
e-NABLE: volunteers worldwide making free, 3D printed prosthetics
Innovation Fellow, JMK Innovation Fund
Reply all
Reply to author
Forward
Message has been deleted
0 new messages