Home » Extra libraries, Code snippets, applications etc. » U++ Esc Interpreter, Esc Macros and templates » bug in Esc manual page?
bug in Esc manual page? [message #2107] |
Sat, 01 April 2006 14:06 |
hojtsy
Messages: 241 Registered: January 2006 Location: Budapest, Hungary
|
Experienced Member |
|
|
In Esc manual page there is this line:
s[1, -1] = "xXx"; // s is now "1xXx4"
Is -1 the slice element count here? I supposed that it could only be positive number.
I also think that this other example has some error. How do the interpreter know in the last line that x means var1.x ?
var.x = 0;
var.Next = @() { .x++; };
var.Next(); // var.x is now 1
var1.x = 0;
var.Next()! x; // var1.x is now 1
BTW, I tried searching for esc files in the U++ installation, to see some examples, but there seems to be none. Maybe some example files could be put in, to make the syntax and usage more straightforward. How do you use Esc in a C++ application, how are the functions are invoked, and how are the return values retrieved? Is there a connection between Esc and Usc? Usc files seems to have a different syntax than the one desribed for Esc. Is there a manual for Usc?
[Updated on: Thu, 04 May 2006 17:16] by Moderator Report message to a moderator
|
|
|
Re: bug in Esc manual page? [message #2112 is a reply to message #2107] |
Sat, 01 April 2006 16:17 |
|
mirek
Messages: 13980 Registered: November 2005
|
Ultimate Member |
|
|
hojtsy wrote on Sat, 01 April 2006 07:06 | In Esc manual page there is this line:
s[1, -1] = "xXx"; // s is now "1xXx4"
Is -1 the slice element count here? I supposed that it could only be positive number.
I also think that this other example has some error. How do the interpreter know in the last line that x means var1.x ?
var.x = 0;
var.Next = @() { .x++; };
var.Next(); // var.x is now 1
var1.x = 0;
var.Next()! x; // var1.x is now 1
BTW, I tried searching for esc files in the U++ installation, to see some examples, but there seems to be none. Maybe some example files could be put in, to make the syntax and usage more straightforward. How do you use Esc in a C++ application, how are the functions are invoked, and how are the return values retrieved? Is there a connection between Esc and Usc? Usc files seems to have a different syntax than the one desribed for Esc. Is there a manual for Usc?
|
Documentation bugs - fixed (negative index is possible, but it should be ":" slice, and "var.Nect() ! var1" instead.
I will try to create some reference\Esc soon.
Usc / Esc relation - Usc is Esc "application" - it is using Esc interpreter as "engine", but (exactly in a Esc design direction - it is "Embeddable Script" adds more syntax to it. But the actual code (in both widget descriptions and TheIDE macros) is Esc.
Mirek
|
|
|
Re: bug in Esc manual page? [message #2247 is a reply to message #2112] |
Wed, 05 April 2006 10:45 |
|
mirek
Messages: 13980 Registered: November 2005
|
Ultimate Member |
|
|
OK, reference/EscDev is the "introductory" Esc example. It does not cover "objects" and uses just trivial script interpretation (without extensions, as with usc)
I will yet have to find some nice simple examples to demonstrate those....
#include <Esc/Esc.h>
void SIC_Print(EscEscape& e)
{
if(e[0].IsArray())
Cout() << (String) e[0];
else
if(e[0].IsNumber())
Cout() << e[0].GetNumber();
else
if(!e[0].IsVoid())
e.ThrowError("invalid argument to 'Print'");
}
void SIC_Input(EscEscape& e)
{
e = ReadStdIn();
}
void SIC_InputNumber(EscEscape& e)
{
e = atof(ReadStdIn());
}
CONSOLE_APP_MAIN
{
ArrayMap<String, EscValue> global;
Escape(global, "Print(x)", SIC_Print);
Escape(global, "Input()", SIC_Input);
Escape(global, "InputNumber()", SIC_InputNumber);
StdLib(global);
try {
Scan(global, LoadFile(GetDataFile("script.esc")));
Execute(global, "main", INT_MAX);
}
catch(CParser::Error e) {
Cout() << "ERROR: " << e << "\n";
}
}
demonstration Esc script (script.esc):
getnumber()
{
for(;;) {
h = InputNumber();
if(h > 0)
return h;
Print("Please enter a positive number!\n");
}
}
main() {
Print("What is your name?\n");
name = Input();
Print("Hi " + name + "!\n");
Print("How tall are you? (in cm please!)\n");
h = getnumber();
Print("What is your weight? (in kg please!)\n");
w = getnumber();
bmi = w / (h * h / 10000);
Print("Your body mass index is " + to_string(bmi) + "\n");
Print(name + ", ");
if(bmi >= 35)
Print("you are morbidly fat!!!");
else
if(bmi >= 30)
Print("you are fat!!!");
else
if(bmi >= 25)
Print("you are overweight!");
else
if(bmi >= 18.5)
Print("your weight is OK.");
else
Print("your are too slim!");
Print("\nThanks for a nice chat!\n");
}
Mirek
|
|
|
|
|
Goto Forum:
Current Time: Thu May 16 19:03:15 CEST 2024
Total time taken to generate the page: 0.02656 seconds
|