characters/struct/enum/examples in the Dao

4 views
Skip to first unread message

Sam Hu

unread,
Aug 4, 2008, 9:47:57 PM8/4/08
to eC Programming Language
Hi Jerome ,

I am reading the Dao and really looking forward to your finishing it
as soon as possible.

Some questions from the book:
1.how to output Chinese set using printf(),in my pc,it does not work
properly,for example:
class appRun:Application
{
void Main()
{
char* name="道德经";
printf("You have input %s\n",name);
}
}
2.Struct parameter in a function is passed by reference by default,if
want to pass by value,use add struct key word.For example:
struct Book{};
void Read(Book book);//pass by reference
void Read(struct Book book);//pass by value;
Am I right?if yes,then the problem I met is that compile failure with
below message:
structApp.ec:21: error: invalid type argument of '->' (have 'struct
Book')
structApp.ec:22: error: invalid type argument of '->' (have 'struct
Book)
structApp.ec:27: error: incompatible type for argument 1 of 'Read'

3.
1).enum examples in the book
enum Planet{mercury,venus,earth,mars,jupiter,saturn,uranus,neptune};
enum PlanetOrDwartPlanet:Planet{ceres,pluto,eris};
Your comments in the book say that ceres will be 8,and so on.But when
I pint it ,it is 0.
2).Is it possible to add implementation something like
enum.toString() to print the enum variable's rep. content other than
the value in integer.For example:
Planet p=mercury;
printf("%d\n",p)//===>output is 0;
printf(%s\n",p.toString())===>output is :mercury.

Regards,
Sam


Jerome St-Louis

unread,
Aug 4, 2008, 10:37:06 PM8/4/08
to ec-programm...@googlegroups.com, SamHu...@gmail.com

2008/8/4 Sam Hu <SamHu...@gmail.com>


Hi Jerome ,

I am reading the Dao and really looking forward to your finishing it
as soon as possible.

I'm sorry it might take a bit of time :(
I am quite busy with the development of the new features...
Right now working on the eC templates, and then I have to finish a few things for the open source release...
I will try to make some steady progress however.
 

Some questions from the book:
1.how to output Chinese set using printf(),in my pc,it does not work
properly,for example:
class appRun:Application
{
  void Main()
 {
   char* name="道德经";
   printf("You have input %s\n",name);
 }
}

That is a problem with the Windows operating system. The Windows console doesn't support UTF-8. Use Linux :)
Or forget about pritnf, and output to an Ecere EditBox control instead. (editBox.Printf() )

 
2.Struct parameter in a function is passed by reference by default,if
want to pass by value,use add struct key word.For example:
struct Book{};
void Read(Book book);//pass by reference
void Read(struct Book book);//pass by value;
Am I right?if yes,then the problem I met is that compile failure with
below message:
structApp.ec:21: error: invalid type argument of '->' (have 'struct
Book')
  structApp.ec:22: error: invalid type argument of '->' (have 'struct
Book)
  structApp.ec:27: error: incompatible type for argument 1 of 'Read'

It is possible that the book (Still unpublished, remember :P) assumes ideals which do not yet work properly.
However if it there is indeed some sample code in the book which does not compile, please report a bug on the bug tracker http://www.ecere.com/mantis/
and attach the offending source code as a file.
 

3.
 1).enum examples in the book
 enum Planet{mercury,venus,earth,mars,jupiter,saturn,uranus,neptune};
enum PlanetOrDwartPlanet:Planet{ceres,pluto,eris};
Your comments in the book say that ceres will be 8,and so on.But when
I pint it ,it is 0.

Interesting :) I will check it :) Maybe it is a bug also.
 
2).Is it possible to add implementation something like
enum.toString() to print the enum variable's rep. content other than
the value in integer.For example:
 Planet p=mercury;
 printf("%d\n",p)//===>output is 0;
 printf(%s\n",p.toString())===>output is :mercury.

In the new release I am working on facilitating this.
Right now every data type as an "OnGetString" method, which however requires a char buffer and 2 other parameters

char buffer[4096];
char * string;
Planet p = mercury;
string = p.OnGetString(buffer, null, null);

The problem with a simple ToString" method has to do with leaking the string... eC needs a better string solution which is unfortunately not there yet :(
But I am hoping to provide nicer utility function in the release 0.43 such as a "PrintLn" and an easier "ToString" method as well.

 
Cheers,

Jerome

Joseph Adams

unread,
Aug 4, 2008, 10:42:08 PM8/4/08
to ec-programm...@googlegroups.com
> 1.how to output Chinese set using printf(),in my pc,it does not work
> properly,for example:
> class appRun:Application
> {
> void Main()
> {
> char* name="道德经";
> printf("You have input %s\n",name);
> }
> }

My guess is that your command line may not be set to UTF-8, which is
the charset consistently used throughout Ecere. Try making a form,
putting an EditBox in it, and using editBox.SetText to set it to the
contents. My guess is that this will render correctly. In any case,
see if you can configure your command line to use UTF-8.

> 3.
> 1).enum examples in the book
> enum Planet{mercury,venus,earth,mars,jupiter,saturn,uranus,neptune};
> enum PlanetOrDwartPlanet:Planet{ceres,pluto,eris};
> Your comments in the book say that ceres will be 8,and so on.But when
> I pint it ,it is 0.

Indeed, I can confirm this. Not only does ceres start at zero, but
PlanetOrDwartPlanet::enumSize is 3 instead of 8+3 = 11.

> 2).Is it possible to add implementation something like
> enum.toString() to print the enum variable's rep. content other than
> the value in integer.For example:
> Planet p=mercury;
> printf("%d\n",p)//===>output is 0;
> printf(%s\n",p.toString())===>output is :mercury.


I agree. Moreover, perhaps the array of all the enum values should be
available, too:

char *enumNames[] = Planet::enumNames; //contains this array:
{"mercury", "venus", "earth", "mars", "jupiter", "saturn", "uranus",
"neptune"}

However, I'd imagine the .toString would be convenient for a whole lot
of applications, so this would be an extension rather than a
substitute. Planet::enumNames[p] is a little unclear :)

Sam Hu

unread,
Aug 5, 2008, 5:30:15 AM8/5/08
to eC Programming Language
Hi both,

Appreciate again.

1.A silly question:how to set command line to UTF-8?-:)
2.I am more and more greedy now.How about operator overloading and
multi-cast delegate,-:)

Regards,
Sam

QUAN

unread,
Aug 5, 2008, 7:24:37 AM8/5/08
to ec-programm...@googlegroups.com
Hi Sam,

For the UTF-8 question...

It seems that you are using Windows, then...

First, if you could check the
[ControlPanel->RegionalAndLanguageOptions->Language->TextServiceAndInputLanguages->Detail->Advanced],
then make sure that options in the [CompatibilityConfiguration] is
checked, and the [SystemConfiguration->TurnOffAdvancedTextServices] is
unchecked.

Then, go to [ControlPanel->Display->Appearance->Advanced], and make
sure all window texts are using a font that support UTF-8.

It could happen that the system wants you to put back in your
installation CD if you are using one of the European language versions
of Windows.

Try Ubuntu pal. If I can also suggest.

Regards
Quan


2008/8/5 Sam Hu <SamHu...@gmail.com>:

--
********************************************
What is a bird?
--"Grzimek's Encyclopedia of Birds".
********************************************

Sam Hu

unread,
Aug 5, 2008, 8:15:46 AM8/5/08
to eC Programming Language
Hi QUAN,

Thanks.

For Chinese font,I tried what you said but still failed ,I am
confident have done everything you've said;

For Linux,I have Fedoa Core 5 on hand for a very long time and once
installed and played for a while,but finally get back to Windows for 2
reasons:
1.for work purpose to maximum compatible to company environment,but
this is not the main reason;
2.Could anybody give me a reason the Linux is better ?I could not find
it ,maybe becoz I just tried for a while.

Regards,
Sam

On Aug 5, 7:24 pm, QUAN <longquan1...@gmail.com> wrote:
> Hi Sam,
>
> For the UTF-8 question...
>
> It seems that you are using Windows, then...
>
> First, if you could check the
> [ControlPanel->RegionalAndLanguageOptions->Language->TextServiceAndInputLan-guages->Detail->Advanced],
> then make sure that options in the [CompatibilityConfiguration] is
> checked, and the [SystemConfiguration->TurnOffAdvancedTextServices] is
> unchecked.
>
> Then, go to [ControlPanel->Display->Appearance->Advanced], and make
> sure all window texts are using a font that support UTF-8.
>
> It could happen that the system wants you to put back in your
> installation CD if you are using one of the European language versions
> of Windows.
>
> Try Ubuntu pal. If I can also suggest.
>
> Regards
> Quan
>
> 2008/8/5 Sam Hu <SamHu.Sa...@gmail.com>:
> ********************************************- Hide quoted text -
>
> - Show quoted text -

Jerome St-Louis

unread,
Aug 5, 2008, 12:00:48 PM8/5/08
to ec-programm...@googlegroups.com
Hi Sam,

The truth is that Windows console simply doesn't support UTF-8, as I found out recently trying to set it up myself...
There was a hack which apparently worked at one point, setting the codepage to a particular ID which represents UTF-8.

See the following:

http://www.google.ca/search?hl=en&safe=off&q=SetConsoleOutputCP+utf-8&btnG=Search&meta=

http://blogs.msdn.com/michkap/archive/2007/05/11/2547703.aspx

http://www.tek-tips.com/viewthread.cfm?qid=1428936&page=2

http://msdn.microsoft.com/en-us/library/ms686036(VS.85).aspx

SetConsoleOutputCP( 65001 ) // that is supposed to set the console to UTF-8

However that command fails for me.

Please let me know if you do manage to make it work :)


Why is Linux better? This particular thing is just one example...
The fact that Linux is open and free is a big plus also.

Operator Overloading:

I'm hoping to support it in a future version of eC. However at the moment much can be done with the "conversion properties" of eC for scalar types, which would normally require operator overloading if they were C++ classes. Related units can be added, subtracted together.

For support in Vectors per example, I will have to add extra support to specify how vectors are to be operated upon...
Here's some sample code:


void Main()
{
   ColorRGB a = Color { 255, 0, 0 };
   Color c = ColorRGB { 0.35f, 1.0f, 1.0f };
   ColorRGB a = Red;
   ColorHSV a = ColorHSV { Degrees{90}, 100, 100 };
   ColorHSV a = ColorHSV { 90, 100, 100 };
   ColorRGB a = ColorHSV { 90, 100, 100 };
   ColorRGB a = ColorHSV { Degrees { 90 }, 100, 100 };
   Color a = ColorHSV { 100, 40, 30 };
   Color a = ColorHSV { 0, 50, 100 };
   Color a = ColorRGB { 1, 0.3f, 0.3f };
   Color c = ColorRGB { 0.35f, 1.0f, 1.0f };
   ColorRGB a = Red;
   ColorRGB a = ColorHSV { 1, 0.3f, 0.3f };
   ColorCMYK a = ColorHSV { 90, 60, 40 };
   ColorLab a = Red;
   ColorHSV a = ColorHSV { Pi/8, 100, 100 };
   ColorHSV a = ColorRGB { 1, 0.3f, 0.3f };
   ColorHSV a = Color { 40, 130, 30 };  
   ColorHSV a = ColorRGB { 40/255.0f, 130/255.0f, 30/255.0f };  
   ColorHSV a = Red;
   ColorHSV a = Indigo;
   ColorHSV a = ColorLab { 30, 60, -40 };
   ColorHSV a = ColorRGB { 1, 0.3f, 0.3f };
   ColorHSV a = Color { 40, 130, 30 };
   ColorHSV a = ColorLab { 40, 60, 30 };
   ColorHSV a = Red;
   Color a = ColorHSV { a, 40, 30 };
   double a = 4 + Pi;
   double a = Pi + 4;
   double a = 4 + Pi + 0;
   double a = Pi + 4 + 0;
   double a = 0 + 4 + Pi;
   double a = 0 + Pi + 4;
   double a = Radians{0} + Pi;
   double a = Degrees{0} + Degrees{30};
   Degrees a = Radians{Pi/4} + 45;
   Degrees a = Radians{Pi/4} + 20 + Degrees{30};  
   Degrees a = Radians{Pi/4} + Pi/8 + Degrees{30} + Pi/4;
   Degrees a = Radians{0} + Pi;
   Degrees a {Radians{Pi/2}};
   double a = Radians{Pi/4} + Degrees{30};    // Make this a warning...
   double a = Degrees{30} + Radians{Pi/4};    // Make this a warning...
   double a = (Degrees)Radians{Pi};
   Degrees a = Radians{Pi/2};
   Degrees a = Radians{Pi/4};
   double a = (Radians)Degrees{45};  
   double a = Degrees{30} / 4;
   double a = Degrees{30} + Pi/4;      // This should generate a warning...
   double a = Degrees{30} + Pi/8 ;     // This should generate a warning...
   double a = Radians{Pi/4} + Pi/8 + Degrees{30} + Pi/4; // This should generate a warning...
   Radians a = Degrees{30};

   Radians a = (Radians)Degrees{45} * 4;
   Radians a = Degrees{45} * 4;
   Radians a = Degrees{20} + 25;

   Degrees a = Degrees{Radians{10}};

   Degrees a = Degrees{60};
   Radians a = Degrees{Radians { Pi/2 }};

   Radians a = Degrees{Pi/2};
   double a = (Degrees) (Pi/4);
   Degrees a;
   Radians b = a;

   double a = (Degrees)Radians{Pi};
   Degrees a = Pi/4;
   double a;
   double e = Degrees{60};
   double e = Degrees{a};

   double dbl;
   Degrees deg;

   Degrees a = Degrees { dbl };
   Degrees a = Degrees { deg };
   Degrees a = Degrees { Degrees { dbl } };
   Degrees a = Degrees { a };

   Degrees a = Degrees { Degrees { 30 } };
   Degrees a = Degrees { 60 };
   Degrees c = Radians{1.40};
   Degrees d = Radians{1.40} + 10;
   double a;
   Degrees a;
   double f = a;
   Degrees b = Pi/4;

   Angle a = Degrees{30};
   Radians a = Degrees{30};
   Degrees yo = Degrees{30} + Radians{30};
   Degrees a = Degrees { Radians { 1.40 } };    // 1.40
   Degrees a = Degrees { 30 };    // 30 degrees in radians

   Feet b = Meters{5};
   Meters a = Feet{5 + 8/12.0};
   double a = (Meters)Feet{5 + 8/12.0};

   double a = Feet{5};

   WorldPoint a = PolarPoint { 30, 10 };
   PolarPoint a = WorldPoint { 50, 40 };
   GeoPoint a { 50, 30 };

   double a = Degrees{20} + 25;
   double a = 25 + Degrees{20};

   (Radians)Degrees{45} * 4;
   (double)(Degrees{20} + 25);

   (double)(Degrees{20} + 25);

   (double)(25 + Degrees{20});

   (double)(25 + Degrees{20});

   (double)(Feet)Meters{5};
   (double)(Degrees)Radians{5};
}

Multi-cast delegate: you're quite far now... Is this a C# specific thing?
eC is meant to be an extension to C, and as such this can probably be done with regular C function pointers.
Super type safety is not a primary design goal of eC...

Regards,

Jerome



Sam Hu

unread,
Aug 5, 2008, 8:52:03 PM8/5/08
to eC Programming Language
Hi Jerome,

Learning...
One more question:How to pop up a messagebox when one click on a
control,say a button,just like :
MessageBox(NULL,"Title","msg",MB_INFORMATION);



Regards,
Sam

On Aug 6, 12:00 am, "Jerome St-Louis" <jerstlo...@gmail.com> wrote:
> Hi Sam,
>
> The truth is that Windows console simply doesn't support UTF-8, as I found
> out recently trying to set it up myself...
> There was a hack which apparently worked at one point, setting the codepage
> to a particular ID which represents UTF-8.
>
> See the following:
>
> http://www.google.ca/search?hl=en&safe=off&q=SetConsoleOutputCP+utf-8...

Jerome St-Louis

unread,
Aug 5, 2008, 9:37:34 PM8/5/08
to ec-programm...@googlegroups.com
   Button button1
   {
      this, text = "button1";

      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
      {
         MessageBox { text = "Title", contents = "msg", type = ok }.Modal();
         return true;
      }
   };

Sam Hu

unread,
Aug 6, 2008, 3:19:57 AM8/6/08
to eC Programming Language
Hi Jerome,

Great,how to adding an icon in the MessageBox?I searched the API but
no found such enumeration.

Regards,
Sam

Jerome St-Louis

unread,
Aug 6, 2008, 7:30:31 AM8/6/08
to ec-programm...@googlegroups.com
Hi Sam,

There is no built in way to add an icon to the MessageBox.

However you can write a new class deriving from MessageBox, and override it to display an icon in the OnRedraw method, or simply by inserting a Picture control inside. You can have an array of icons mapping to the "type" MessageBox enumeration.

class MyIconMessageBox :  MessageBox
{
   Picture icon { this, image = ":icon.png", position = ... };

   or

   void OnRedraw(Surface surface)
   {
      MessageBox::OnRedraw(surface); // Chain default MessageBox OnRedraw
      // Draw Icon Here
   }
}

Regards,

Jerome
Reply all
Reply to author
Forward
0 new messages