vibe.d selectively include attribute into tag using diet template
Hi, I know that one can do the following: tag(attribute='#{dexpression}') But, is there a way to deal with attributes that don't get assigned values. That is, is there a way to produce or depending on a boolean variable? Of course one can do: - if (booleanVariable) tag(attribute) include ... - if (!booleanVariable) tag include ... But this seems rather messy.
Re: vibe.d selectively include attribute into tag using diet template
On 2/27/21 12:48 PM, JG wrote: Hi, I know that one can do the following: tag(attribute='#{dexpression}') But, is there a way to deal with attributes that don't get assigned values. That is, is there a way to produce or depending on a boolean variable? Of course one can do: - if (booleanVariable) tag(attribute) include ... - if (!booleanVariable) tag include ... But this seems rather messy. Yes, if you assign a boolean value to it directly, then if true, the attribute is included, if not, it's not. e.g.: tag(attribute=booleanVariable) Note the lack of quotes. If you us an expression without quotes in diet, it becomes an interpolation. In the special case that it's a boolean, it becomes a switch to tell whether to include the attribute or not. If it's a complex expression you might need parentheses: tag(attribute=(booleanVariable ? true : false)) -Steve
Re: vibe.d selectively include attribute into tag using diet template
On Saturday, 27 February 2021 at 19:12:55 UTC, Steven Schveighoffer wrote: Yes, if you assign a boolean value to it directly, then if true, the attribute is included, if not, it's not. e.g.: tag(attribute=booleanVariable) Note the lack of quotes. Thank you very much for this. If you use an expression without quotes in diet, it becomes an interpolation. Would you mind explaining in more detail what this means? How could one use this, other than with booleans?
How can I make this work?
I'm using a windows callback function where the user-defined value is passed thought a LPARAM argument type. I'd like to pass my D array then access it from that callback function. How is the casting from LPARAM to my type array done in that case? for example, I need something like this to work: int[] arr = [1, 2, 3]; long l = cast(long) cast(void*) arr.ptr; int[] a = cast(int[]) cast(void*) l;
Re: How can I make this work?
On Sunday, 28 February 2021 at 07:05:27 UTC, Jack wrote: I'm using a windows callback function where the user-defined value is passed thought a LPARAM argument type. I'd like to pass my D array then access it from that callback function. How is the casting from LPARAM to my type array done in that case? for example, I need something like this to work: int[] arr = [1, 2, 3]; long l = cast(long) cast(void*) arr.ptr; int[] a = cast(int[]) cast(void*) l; Should already work like that. Just be aware that array can be garbage collected if no references for it are kept somewhere else between set callback and the actual call, otherwise you can get some random garbage. Also be aware that such casts 99% basically a speculation, there is no guarantee that returned data is actually an int[].