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)?
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 previous 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

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
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: Wed May 15 08:53:00 CEST 2024

Total time taken to generate the page: 0.02569 seconds