About Monkey 2 › Forums › Monkey 2 Development › Bug or not for struct Extension
Tagged: extension
This topic contains 6 replies, has 2 voices, and was last updated by
gcmartijn 2 years, 7 months ago.
-
AuthorPosts
-
September 11, 2016 at 7:34 pm #3881
Using this for example
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445Namespace myapp#Import "<std>"#Import "<mojo>"Using std..Using mojo..Struct Vec2<T> ExtensionMethod Set:Vec2<T>(_x:Float,_y:Float )Print "Self.X"+Self.XPrint "Self.X"+Self.xPrint "_x"+_xSelf.X = _xSelf.Y = _yPrint "Self.X"+Self.XPrint "Self.X"+Self.xPrint SelfReturn SelfEndEndClass MyWindow Extends WindowMethod OnRender( canvas:Canvas ) OverrideLocal v:Vec2f = New Vec2f(3,4)Print vv.Set(10,10)Print v.x ' wrong ?Print v.X ' wrong ?Print v ' wrong ?EndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndOutput
Vec2(3,4)
Self.X 3
Self.X 3
_x 10
Self.X 10
Self.X 10
Vec2(10,10)
3 < wrong ?
3 < wrong ?
Vec2(3,4) < wrong ?Or is it oke because its a struct and I need to return not Self but a new Vec2f() ?
And what is the best thing to use in all the programs:
The vec2f.X or vec2f.x (property or field) they are both the ‘same’September 11, 2016 at 9:21 pm #3882Ok, it turns out you can’t currently write to a struct via an extension method.
I’ll have a look into possibly allowing this later, but for now I’ve added an error message when you attempt to do this.
September 11, 2016 at 9:50 pm #3883Fixed! Needs more testing but I think it’s doable – take that c#!
September 12, 2016 at 5:20 am #3887cool, then a new module for the community is on the way.
September 12, 2016 at 3:48 pm #3906Downloaded the latest version, but its still give the wrong Return Self back.
The output is the same.
What I expect was
Vec2(3,4)
Self.X 3
Self.X 3
_x 10
Self.X 10
Self.X 10
Vec2(10,10)
3 < wrong ? >>> 10
3 < wrong ? >>> 10
Vec2(3,4) < wrong ? >>> Vec2(10,10)September 12, 2016 at 8:17 pm #3910It’s working here as long as I ‘./updatemx2cc.sh’ and ‘./rebuildall.sh’ after that.
Perhaps best to wait until the next binaries update – I’ll do one today.
September 13, 2016 at 5:51 am #3915oke, works here now.
I din’t know that ‘updatemx2cc.sh’ did something more then ‘rebuildall.sh’What I do is not using git, but
1. delete the whole monkey directory.
2. download the git zipfile
3. run rebuildall.shbut as I can see now, updatemx2cc.sh does the trick and does something more.
And about my other question, I a other topic someone said that using a Field is faster than accessing a Property. With that in mind I will use fields first and then property’s.
-
AuthorPosts
You must be logged in to reply to this topic.