About Monkey 2 › Forums › Monkey 2 Programming Help › Reading mojo decls…
This topic contains 7 replies, has 3 voices, and was last updated by
DruggedBunny
1 year, 8 months ago.
-
AuthorPosts
-
August 3, 2017 at 6:21 pm #9721
I was hoping to grab the list of consts from the Color type to apply randomly to a bunch of cubes! The reflection docs say you can only use this on user-defined types, but I’m assuming the mojo types would fall under this too…
The bananas example seems to be able to get a list of ALL types and their decls (including consts, I notice), but I can’t figure out how to just list the decls of one specific type…
Monkey12345678910111213141516171819202122232425#Import "<reflection>"#Import "<std>"Using std..Function Main ()' Print TypeInfo.GetType ("Color") ' Nope!Local ct:TypeInfo = Typeof <Color>If ctPrint "OK!" ' This works!' This... not so much...For Local decl:DeclInfo = Eachin ct.GetDecls ()Print declNextEndifEndThe aim being to strip out these and stick in a stack/list/array…
Monkey123456789Struct ColorConst None:=New Color( 0,0,0,0 ) ' I'll have that Color!Const Black:=New Color( 0,0,0 ) ' And that!Const Grey:=New Color( .5,.5,.5 ) ' And that!...Any assistance greatly appreciated and all that!
(This was with latest dev branch yesterday.)
August 4, 2017 at 3:28 am #9722From Limitations section in blog:
You can still use other types (structs etc) with variants etc, but you wont be able to inspect their members.
Print TypeInfo.GetType (“Color”)
For type-by-name you should to specify full namespace, like std.graphics.Color.
August 4, 2017 at 7:20 am #9723Nah, I’ve tried that:
Monkey1234567891011#Import "<reflection>"#Import "<std>"Using std..Function Main ()Print TypeInfo.GetType ("std.graphics.Color") ' Nope!EndThis results in “Caught signal:Memory access violation”.
August 4, 2017 at 11:36 am #9727Mark said improving reflection is one of near goal.
August 4, 2017 at 5:58 pm #9728Yeah, I did read that, so will just wait, was just amusing myself anyway… at least it sounds like I was using it properly!
August 5, 2017 at 3:41 am #9730Weird, will look into it.
August 10, 2017 at 11:05 pm #9782Ok, the main issue here is that Color is a struct, and structs aren’t currently reflected (hence the error ‘not a class or interface’).
This wasn’t an issue in bmx of course because it didn’t have structs, but I am yet to get them working properly with reflection in monkey2. I do plan to spend more time on reflection soon though and will be looking into this.
August 11, 2017 at 7:28 am #9788Ahh, cool… thanks, Mark.
-
AuthorPosts
You must be logged in to reply to this topic.