Nullable Int, Double, Float ?

About Monkey 2 Forums Monkey 2 Programming Help Nullable Int, Double, Float ?

This topic contains 2 replies, has 2 voices, and was last updated by  Diffrenzy 2 years, 1 month ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #7323

    Diffrenzy
    Keymaster

    How do I do nullable types in MX2? Basically I’d like to have the equivalent of c#’s int?, float? etc.

    Is there a way in MX2, without wrapping in a class, and ending up with a nullabletype.Value = xxx like syntax?

    (I’m deserializing/serializing a generic type to xml, and need to only read/write values when they are present.)

    PS: Speaking of nulls, I’d like to be able to do:

    like I can with types. Is that a builtin given for structs, or could it be added to MX2?

    #7335

    Mark Sibly
    Keymaster

    There are no nullable types in mx2. There are variants though – see reflection in monkey2 language docs.

    could it be added to MX2?

     

    quite possibly – can you post an issue on github?

    #7344

    Diffrenzy
    Keymaster

    Thanks Mark, I’ve put the Null issue on github (and also a request for the Elvis operator, which I really enjoy in C# )

    Thanks for pointing me towards Variants. They a not a perfect for for my intended use, so I’ve ended up copying std.geom Vec2 and making a Vec1 struct, by removing the y vals and a few methods. If it’s not too weird, maybe MX2 could come with a Vec1 struct , to have a standard for float/int boxing ?

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.