Hey, I want to write a visual scripting tool (with eclipse) and for that I need a function with which I can find all functions in the sketch and get the parameters.
Processing does the same, if you press CTRL and space bar, then variables and functions are suggested (with parameters).
Here’s a picture:
For example, I call getFunctions () in the tool script and then it should give me an array with all the functions that are open in processing.
The resolution is analogous to the used for methods
import java.lang.reflect.Field;
import java.util.Collections;
Foo foo;
String something;
int somthingElse;
void setup() {
println("\n***** PAPPLET FIELDS: *****");
printFields(getClass().getFields());
println("\n***** USER FIELDS: *****");
printFields(getClass().getDeclaredFields());
println("\n***** USER CLASS FIELDS: *****");
for (Class c : getClass().getDeclaredClasses()) printFields(c.getDeclaredFields());
exit();
}
String clean(String str) {
str = str.substring(str.lastIndexOf('.') + 1);
if (str.contains("$")) str = str.substring(str.indexOf('$') + 1); // get rid of the sketch class name and keep only the child class name
return str.replaceAll("[^\\w]", "");
}
void printFields(Field[] list) {
ArrayList<String> result = new ArrayList();
for (Field f : list) {
String name = clean(f.getName());
String type = clean(f.getType().toString());
result.add(name + " : " + type);
}
Collections.sort(result);
for (String s : result) println(s);
}
class Foo {
int fooInt;
boolean fooState;
Foo fooInstance;
}