We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › PApplet.parseInt
Page Index Toggle Pages: 1
PApplet.parseInt (Read 1308 times)
PApplet.parseInt
May 8th, 2009, 3:58am
 
Can anyone explain to me where to use this code? and what it does?

Any advice would be gratefully recieved.

Thanks
Re: PApplet.parseInt
Reply #1 - May 8th, 2009, 5:43am
 
I would be curious why you ask that (and where you saw it)...

Actually, if you write a simple sketch like:
Code:
String s = "4564.4";
int n = int(s);

println(n);

Processing will generate the following Java code:
Code:
String s = "4564.4";
int n = PApplet.parseInt(s);

println(n);

noLoop();

(in a generated setup() function), using the Antlr pre-processor.
So basically you can just look the int() reference to see what parseInt() does. That's just an (hidden) implementation detail.

I think this pre-processing step is necessary (for int(), float() and similar casting functions) because these are Java reserved words, so one cannot use them as function names.
Re: PApplet.parseInt
Reply #2 - May 10th, 2009, 9:03am
 
Where can be founded theese kind of hidden implementation details?
Re: PApplet.parseInt
Reply #3 - May 10th, 2009, 9:34am
 
you can browse the javadocs,
http://dev.processing.org/reference/everything/index.html
(click on PApplet in the left frame and then start looking for parseInt)
or you can look at the source directly:
http://dev.processing.org/source/index.cgi/trunk/processing/core/src/processing/core/PApplet.java?view=markup

however, you can't rely on every function listed there, some might be changed or removed in the future.... (i guess the rule is "everything that's not in the normal reference might change at any point").
Page Index Toggle Pages: 1