mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
conditionally add code for main() via the preproc
This commit is contained in:
@@ -1997,6 +1997,7 @@ public class Sketch {
|
||||
File stubFile =
|
||||
new File(dotAppFolder, "Contents/MacOS/JavaApplicationStub");
|
||||
String stubPath = stubFile.getAbsolutePath();
|
||||
// will work on osx or *nix, but just dies on windows, oh well..
|
||||
Runtime.getRuntime().exec(new String[] { "chmod", "+x", stubPath });
|
||||
|
||||
// set the jar folder to a different location than windows/linux
|
||||
|
||||
@@ -461,6 +461,11 @@ public class PdeEmitter implements PdeTokenTypes
|
||||
|
||||
// to output, use print(child) on each of the four
|
||||
|
||||
String methodName = methodNameChild.getText();
|
||||
if (methodName.equals("main")) {
|
||||
PdePreprocessor.foundMain = true;
|
||||
}
|
||||
|
||||
/*
|
||||
// 1. figure out if this is setup, draw, or loop
|
||||
String methodName = methodNameChild.getText();
|
||||
|
||||
@@ -153,7 +153,8 @@ public class PdePreprocessor {
|
||||
static public final int ACTIVE = 1; // formerly INTERMEDIATE
|
||||
static public final int JAVA = 2; // formerly ADVANCED
|
||||
// static to make it easier for the antlr preproc to get at it
|
||||
static public int programType = -1;
|
||||
static public int programType;
|
||||
static public boolean foundMain;
|
||||
|
||||
Reader programReader;
|
||||
String buildPath;
|
||||
@@ -191,6 +192,9 @@ public class PdePreprocessor {
|
||||
public String write(String program, String buildPath,
|
||||
String name, String codeFolderPackages[])
|
||||
throws java.lang.Exception {
|
||||
// need to reset whether or not this has a main()
|
||||
foundMain = false;
|
||||
|
||||
// if the program ends with no CR or LF an OutOfMemoryError will happen.
|
||||
// not gonna track down the bug now, so here's a hack for it:
|
||||
if ((program.length() > 0) &&
|
||||
@@ -362,7 +366,7 @@ public class PdePreprocessor {
|
||||
emitter.setOut(stream);
|
||||
emitter.print(rootNode);
|
||||
|
||||
writeFooter(stream);
|
||||
writeFooter(stream, name);
|
||||
stream.close();
|
||||
|
||||
// if desired, serialize the parse tree to an XML file. can
|
||||
@@ -432,13 +436,7 @@ public class PdePreprocessor {
|
||||
|
||||
if (programType < JAVA) {
|
||||
// open the class definition
|
||||
out.print("public class " + className + " extends ");
|
||||
//if (opengl) {
|
||||
//out.print("PAppletGL");
|
||||
//} else {
|
||||
out.print("PApplet");
|
||||
//}
|
||||
out.print(" {");
|
||||
out.print("public class " + className + " extends PApplet {");
|
||||
|
||||
if (programType == STATIC) {
|
||||
// now that size() and background() can go inside of draw()
|
||||
@@ -456,12 +454,20 @@ public class PdePreprocessor {
|
||||
*
|
||||
* @param out PrintStream to write it to.
|
||||
*/
|
||||
void writeFooter(PrintStream out) {
|
||||
void writeFooter(PrintStream out, String className) {
|
||||
|
||||
if (programType == STATIC) {
|
||||
// close off draw() definition
|
||||
out.print("noLoop(); ");
|
||||
out.print("}");
|
||||
out.print("} ");
|
||||
}
|
||||
|
||||
if ((programType == STATIC) || (programType < JAVA)) {
|
||||
if (!PdePreprocessor.foundMain) {
|
||||
out.print("static public void main(String args[]) { ");
|
||||
out.print(" PApplet.main(new String[] { \"" + className + "\" });");
|
||||
out.print("}");
|
||||
}
|
||||
}
|
||||
|
||||
if (programType < JAVA) {
|
||||
|
||||
@@ -15,10 +15,17 @@ X just need to override the key events
|
||||
o main() method needs to set layout manager if jexegen is to be used
|
||||
o (msft vm defaults to null layout manager)
|
||||
o also make sure pack() is happening
|
||||
|
||||
_ PApplet.main(new String[] { "TheClass" });
|
||||
_ this will need to detect whether the user has their own main()
|
||||
X PApplet.main(new String[] { "TheClass" });
|
||||
X this will need to detect whether the user has their own main()
|
||||
o or even PApplet.main(new String[] { getClass().getName() });
|
||||
|
||||
_ save code before export, otherwise .pde exported is empty
|
||||
_ ask user ok or cancel to save code before exporting
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=157
|
||||
|
||||
_ documentation
|
||||
_ people using "java" mode must create their own main
|
||||
_ another function named main() is a no-no.. it'll confuse the preproc
|
||||
_ how to handle qtjava in exports?
|
||||
_ need per-platform settings for exports
|
||||
_ opengl needs to export .jnilib for macosx, but no dll and so files
|
||||
@@ -108,10 +115,6 @@ _ be sure to check the "complete" reference
|
||||
_ change bugs.html to issues.html
|
||||
_ and add a redirect in httpd.conf
|
||||
|
||||
_ save code before export, otherwise .pde exported is empty
|
||||
_ ask user ok or cancel to save code before exporting
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=157
|
||||
|
||||
_ properly handle non-ascii chars in p5 folder name
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=49
|
||||
_ or at least warn the user to install somehwere else
|
||||
|
||||
Reference in New Issue
Block a user