Is it possible for custom structs to respond to the format attribute?

I’d like my structs to be able to reflect the format attribute set when declaring them. For example, something like this:

typedef struct {
    int x;
} S <read=ReadS>;

string ReadS(S &s) {
    if (GetDisplayFormat() == DISPLAY_FORMAT_HEX) {
        return Str("%xh", s.x);
    } else {
        return Str("%d", s.x);
    }
}

S s <format=hex>;

Unfortunately, this doesn’t work because the format attribute doesn’t actually alter the current display format, and I haven’t found any methods to get attribute values. Is there any other way to check, inherit, etc the attributes of the declaration?
I can accomplish the same thing using a parameter, but I’d prefer to use the standard attribute instead:

typedef struct (int hex) {
    local int hex = hex;
    int x;
} S <read=ReadS>;

string ReadS(S &s) {
    if (s.hex) {
        return Str("%xh", s.x);
    } else {
        return Str("%d", s.x);
    }
}

S s(1);

Thank you!

Hello TKGP. You are correct that there is no way currently to query the display format setting for a variable. This is something we can add in the future but for right now you’ll have to use a parameter like you described. Cheers!

Graeme
SweetScape Software

1 Like