I’m trying to create a PackingRectangle instance from RectpackSharp but it requires width and height as Integer32 (Unsigned) while I have Integer32. I tried to use CastAs but it didn’t work.
How do I make it work?
I’m trying to create a PackingRectangle instance from RectpackSharp but it requires width and height as Integer32 (Unsigned) while I have Integer32. I tried to use CastAs but it didn’t work.
How do I make it work?
Thanks @sebescudie, it did work. By the way, do you know why CastAs node didn’t work here?
Because u need a conversion, e.g. iobox is int, u can’t cast it to uint because types will be different, but you can covert int to uint
Oh so you mean CastAs cannot convert primitive types (like int, uint, float) but it can convert between actual classes?
Interesting, I didn’t think in this way. When I code, I don’t have to think about this way (below is C# code):
I don’t have details how this is implemented on vl side, but yes c# compiler, would try to convert type, in VL CastAs would try match incoming type to type it’s after. There are other Cast nodes, maybe some of them is closer to c# cast, like HardCast
note the difference between the CastAs (equivalent to the C# as operator) and and HardCast (equivalent to the C# cast expression) nodes.
If that’s the case then HardCast doesn’t work like C# cast expression. Here I am trying to use + operator from Integer 32 unsigned and HardCast is giving me an error:
This should’ve worked, right?
Interesting. CastAs
is implemented using the is
operator, HardCast
does a (T)
on the incoming object
- that might be the issue here, that we deal with a boxing conversion from uint
to object
first which later can’t be cast anymore. Pretty sure taking a generic S
and casting it to T
wouldn’t be an option either. In other words, implementing this in a fully generic way doesn’t seem to be straight forward. Going the explicit route via ToUInt32
seems to be the best option.