Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Extra libraries, Code snippets, applications etc. » U++ Esc Interpreter, Esc Macros and templates » Esc: how to convert from string to number (or integer)?
Esc: how to convert from string to number (or integer)? [message #3055] Fri, 05 May 2006 13:27 Go to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
Esc: how to convert from string to number (or integer)?
Thanks.
Re: Esc: how to convert from string to number (or integer)? [message #3056 is a reply to message #3055] Fri, 05 May 2006 13:33 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
fudadmin wrote on Fri, 05 May 2006 07:27

Esc: how to convert from string to number (or integer)?
Thanks.


Well, either write your library function (see Esc/EscStdLib.cpp) or write it in Esc...

(of course, now this depends what you are currently playing with. If with Esc within TheIDE, later is perhaps the only option...)

Mirek
Re: Esc: how to convert from string to number (or integer)? [message #3057 is a reply to message #3056] Fri, 05 May 2006 13:49 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
luzr wrote on Fri, 05 May 2006 12:33

fudadmin wrote on Fri, 05 May 2006 07:27

Esc: how to convert from string to number (or integer)?
Thanks.


Well, either write your library function (see Esc/EscStdLib.cpp) or write it in Esc...

(of course, now this depends what you are currently playing with. If with Esc within TheIDE, later is perhaps the only option...)

Mirek


I'm trying to write a very clever template... in *.upt,
where the amount of some functions and their names depend on a value entered into custom id field...

[Updated on: Fri, 05 May 2006 13:49]

Report message to a moderator

Re: Esc: how to convert from string to number (or integer)? [message #3058 is a reply to message #3057] Fri, 05 May 2006 13:52 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
If that not exists, then I'll try to write in EscStdLib... It might be more useful later?
Re: Esc: how to convert from string to number (or integer)? [message #3059 is a reply to message #3058] Fri, 05 May 2006 14:37 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
fudadmin wrote on Fri, 05 May 2006 07:52

If that not exists, then I'll try to write in EscStdLib... It might be more useful later?


It might be. I think, as long as there is to_string, there likely should be some sort of atoi (or to_int)?

Go on, do it, post here, I will add it to EscStdLib. (actually, it will be about 5 lines Wink

Mirek
Re: Esc: how to convert from string to number (or integer)? [message #3064 is a reply to message #3059] Fri, 05 May 2006 18:16 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
luzr wrote on Fri, 05 May 2006 13:37

fudadmin wrote on Fri, 05 May 2006 07:52

If that not exists, then I'll try to write in EscStdLib... It might be more useful later?


It might be. I think, as long as there is to_string, there likely should be some sort of atoi (or to_int)?

Go on, do it, post here, I will add it to EscStdLib. (actually, it will be about 5 lines Wink

Mirek


//in EscStdLib.cpp
//aris +8lines
void ESC_to_number(EscEscape& e)
{
	if(e[0].IsArray()){
		String  s=e[0];
		double  d = ScanDouble(s);
		e = e[0].ToNumber(d);
	}
}
//... 

void StdLib(ArrayMap<String, EscValue>& global)
{
	Escape(global, "is_number(value)", ESC_is_number);
	Escape(global, "is_array(value)", ESC_is_array);
	Escape(global, "is_map(value)", ESC_is_map);
	Escape(global, "is_void(value)", ESC_is_void);
	Escape(global, "int(value)", ESC_int);
	Escape(global, "to_string(value)", ESC_to_string);
//aris +1 line
	Escape(global, "to_number(value)", ESC_to_number); 

//...
//in Esc.h
	double                 GetNumber() const     { return IsNumber() ? number : 0; }
	bool                   IsInt() const;
	int                    GetInt() const;
//aris +1 line
	double               ToNumber(double n)   { Free(); number=n; type = ESC_NUMBER; return n;}

10lines=2*5lines ... Smile

I was lazy to go into the details and haven't tested it extensively. But it works for me...
Is it correct from your point of view?

[Updated on: Fri, 05 May 2006 18:16]

Report message to a moderator

Re: Esc: how to convert from string to number (or integer)? [message #3065 is a reply to message #3064] Fri, 05 May 2006 18:24 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
fudadmin wrote on Fri, 05 May 2006 12:16

luzr wrote on Fri, 05 May 2006 13:37

fudadmin wrote on Fri, 05 May 2006 07:52

If that not exists, then I'll try to write in EscStdLib... It might be more useful later?


It might be. I think, as long as there is to_string, there likely should be some sort of atoi (or to_int)?

Go on, do it, post here, I will add it to EscStdLib. (actually, it will be about 5 lines Wink

Mirek


//in EscStdLib.cpp
//aris +8lines
void ESC_to_number(EscEscape& e)
{
	if(e[0].IsArray()){
		String  s=e[0];
		double  d = ScanDouble(s);
		e = e[0].ToNumber(d);
	}
}
//... 

void StdLib(ArrayMap<String, EscValue>& global)
{
	Escape(global, "is_number(value)", ESC_is_number);
	Escape(global, "is_array(value)", ESC_is_array);
	Escape(global, "is_map(value)", ESC_is_map);
	Escape(global, "is_void(value)", ESC_is_void);
	Escape(global, "int(value)", ESC_int);
	Escape(global, "to_string(value)", ESC_to_string);
//aris +1 line
	Escape(global, "to_number(value)", ESC_to_number); 

//...
//in Esc.h
	double                 GetNumber() const     { return IsNumber() ? number : 0; }
	bool                   IsInt() const;
	int                    GetInt() const;
//aris +1 line
	double               ToNumber(double n)   { Free(); number=n; type = ESC_NUMBER; return n;}

10lines=2*5lines ... Smile

I was lazy to go into the details and haven't tested it extensively. But it works for me...
Is it correct from your point of view?


Not quite optimal.... This is simpler and not adding weird methods to EscValue:

void ESC_to_number(EscEscape& e)
{
	if(e[0].IsArray())
		e = ScanDouble((String)e[0]);
}


(now in U++)

Mirek
Re: Esc: how to convert from string to number (or integer)? [message #3067 is a reply to message #3065] Fri, 05 May 2006 18:39 Go to previous message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
That's super! Many thanks! I was worrying about memory leaks... Smile
Previous Topic: Is it possible to use Esc language in *.upt templates?
Next Topic: How to declare a global var without id in *.upt?
Goto Forum:
  


Current Time: Fri Mar 29 09:04:18 CET 2024

Total time taken to generate the page: 0.01768 seconds