Thread overview
Error: unsupported char 0x03
Oct 22, 2013
Agustin
Oct 22, 2013
Agustin
Oct 22, 2013
Adam D. Ruppe
Oct 22, 2013
Agustin
Oct 22, 2013
John Colvin
Oct 22, 2013
bearophile
Oct 22, 2013
Agustin
Oct 22, 2013
Ali Çehreli
October 22, 2013
Trying to use mixin, i get an unsupported char error.

protected template GenMessageGetId(uint id) {
    immutable string GenMessageGetId
        = "public immutable(int) getId() const { \n" ~ id ~ "; \n}";
}

public mixin template Packet(uint id, T...) {
    ...

    private static string buildPacket() {
         ...

         return GenMessageGetId!(id);
    }

    mixin (buildPacket());
}

class MyPacket : Message {
    mixin Packet!(3, ...); -> Error: unsupported char 0x03
}

GenMessageGetId is generating "unsupported char 0x03".
October 22, 2013
On Tuesday, 22 October 2013 at 15:01:20 UTC, Agustin wrote:
> Trying to use mixin, i get an unsupported char error.
>
> protected template GenMessageGetId(uint id) {
>     immutable string GenMessageGetId
>         = "public immutable(int) getId() const { \n" ~ id ~ "; \n}";
> }
>
> public mixin template Packet(uint id, T...) {
>     ...
>
>     private static string buildPacket() {
>          ...
>
>          return GenMessageGetId!(id);
>     }
>
>     mixin (buildPacket());
> }
>
> class MyPacket : Message {
>     mixin Packet!(3, ...); -> Error: unsupported char 0x03
> }
>
> GenMessageGetId is generating "unsupported char 0x03".

protected template GenMessageGetId(uint id) {
    immutable string GenMessageGetId
        = "public immutable(int) getId() const { \nreturn" ~ id ~ ";
\n}";
}
October 22, 2013
On Tuesday, 22 October 2013 at 15:01:20 UTC, Agustin wrote:
>         = "public immutable(int) getId() const { \n" ~ id ~ "; \n}";

You'll probably want to convert id to a string there

import std.conv;

 "public immutable(int) getId() const { \n" ~ to!string(id) ~ ";

and also put in return for that function:
 "public immutable(int) getId() const { \n return " ~ to!string(id) ~ ";


and it should compile. What was happening before is string ~ int implicitly converts the int to a char, and cast(char)(3) isn't a printable character, and isn't allowed in D source code.
October 22, 2013
On Tuesday, 22 October 2013 at 15:01:20 UTC, Agustin wrote:
> Trying to use mixin, i get an unsupported char error.
>
> protected template GenMessageGetId(uint id) {
>     immutable string GenMessageGetId
>         = "public immutable(int) getId() const { \n" ~ id ~ "; \n}";
> }
>
> public mixin template Packet(uint id, T...) {
>     ...
>
>     private static string buildPacket() {
>          ...
>
>          return GenMessageGetId!(id);
>     }
>
>     mixin (buildPacket());
> }
>
> class MyPacket : Message {
>     mixin Packet!(3, ...); -> Error: unsupported char 0x03
> }
>
> GenMessageGetId is generating "unsupported char 0x03".

do you perhaps want to!string(id) ???
October 22, 2013
On Tuesday, 22 October 2013 at 15:05:16 UTC, Adam D. Ruppe wrote:
> On Tuesday, 22 October 2013 at 15:01:20 UTC, Agustin wrote:
>>        = "public immutable(int) getId() const { \n" ~ id ~ "; \n}";
>
> You'll probably want to convert id to a string there
>
> import std.conv;
>
>  "public immutable(int) getId() const { \n" ~ to!string(id) ~ ";
>
> and also put in return for that function:
>  "public immutable(int) getId() const { \n return " ~ to!string(id) ~ ";
>
>
> and it should compile. What was happening before is string ~ int implicitly converts the int to a char, and cast(char)(3) isn't a printable character, and isn't allowed in D source code.

Works great, thanks! :)
October 22, 2013
John Colvin:

> do you perhaps want to!string(id) ???

Or:

id.text

Bye,
bearophile
October 22, 2013
On Tuesday, 22 October 2013 at 15:16:17 UTC, bearophile wrote:
> John Colvin:
>
>> do you perhaps want to!string(id) ???
>
> Or:
>
> id.text
>
> Bye,
> bearophile


I like id.text better than to!string, thanks
October 22, 2013
On 10/22/2013 08:56 AM, Agustin wrote:

> On Tuesday, 22 October 2013 at 15:16:17 UTC, bearophile wrote:
>> John Colvin:
>>
>>> do you perhaps want to!string(id) ???
>>
>> Or:
>>
>> id.text
>>
>> Bye,
>> bearophile
>
>
> I like id.text better than to!string, thanks

Me too but the following looks nice too:

    id.to!string

Ali