Learning chaining

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
582
I'm struggling with understanding how to create a chaining syntax like this with matrix in Cerberus-X, is it possible?

code_language.cerberus:
landsca = AffineMat3f().Translate(p).Rotate(r).Scale(s,s)
 

Holzchopf

Moderator
3rd Party Module Dev
Tutorial Author
Joined
Jul 31, 2017
Messages
484
If all the functions AffineMat3f(), Translate(p), Rotate(r), Scale(s,s) return an object of the same type, then that's possible. The chained methods act on the returned value from the previous function/method, so whatever they return must have these methods.

That's the reason why often functions that mutate the input object also return it (which might seem like an unnecessary redundancy, but only like this, chaining is possible)
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
582
Thanks! Okay so as long as the input and output is the same you can do this for as long as you want?
Here the data is just a normal transform array [ix,iy,jx,jy,tx,ty] so I guess they each fill in / change whatever they need to in the chain?
 
Top Bottom