www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Error: unsupported char 0x03

reply "Agustin" <agustin.l.alvarez hotmail.com> writes:
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".
Oct 22 2013
next sibling parent "Agustin" <agustin.l.alvarez hotmail.com> writes:
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}"; }
Oct 22 2013
prev sibling next sibling parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
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.
Oct 22 2013
parent "Agustin" <agustin.l.alvarez hotmail.com> writes:
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! :)
Oct 22 2013
prev sibling parent reply "John Colvin" <john.loughran.colvin gmail.com> writes:
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) ???
Oct 22 2013
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
John Colvin:

 do you perhaps want to!string(id) ???
Or: id.text Bye, bearophile
Oct 22 2013
parent reply "Agustin" <agustin.l.alvarez hotmail.com> writes:
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
Oct 22 2013
parent =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
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
Oct 22 2013