var.get

Gets the var converted to type T as best it can. T may be constructed from T.fromJsVar, or through type conversions (coercing as needed). If T happens to be a struct, it will automatically introspect to convert the var object member-by-member.

struct var
T
get
(
T
)
()
if (
!is(T == void)
)

Meta

History

On April 21, 2020, I changed the behavior of

var a = null;
string b = a.get!string;

Previously, b == "null", which would print the word when writeln'd. Now, b is null, which prints the empty string, which is a bit less user-friendly, but more consistent with converting to/from D strings in general.

If you are printing, you can check a.get!string is null and print null at that point if you like.

I also wrote the first draft of this documentation at that time, even though the function has been public since the beginning.

On January 1, 2021, I changed get!some_struct to call properties on the var, if a member looks like a function or object, to try to get plain-old-data out. Since the functions are only ever put there by you or by you allowing script, I don't feel too bad about it, but it still might not be ideal for all circumstances, so idk if I'll leave it this way or not.

One thing it helps for though is taking scripted subclasses back into D structs, since the parent class thing is likely to be virtual properties. And having that just work in argument lists is really cool...

Search function for the comment "property getter support" to see the impl.