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 & HelpPrograms › A self writing application...
Page Index Toggle Pages: 1
A self writing application... (Read 1068 times)
A self writing application...
Sep 6th, 2005, 3:10pm
 
I had a feeling this might be impossible. But seeing as every idea I try out recently on my current project I'm too stupid to realise I tried to think of a new idea.

I thought of how I seemed to grasp automata well and wouldn't it be cool if people could come visit me with their own automata and release them on a giant virtual canvas. I thought I might have to write a script language for this though. Then I thought, "hang on, I can just use the magic -include- command in php to drag in any old jibberish wherever I want, can't I do that in Processing?" I then thought that if each new automata was an object file that object file could be pulled in using a hub file that would run all the objects. There would be no need for a script language, people could write the automata in Processing syntax!

But I would need some kind of self adapting code in order to pull in the new objects. I can't seem to use the "import" command, I don't know how it works. I noticed that when Processing compiles tabs it just pads them on the end of the .java file. That gave me an idea. I thought that it should be possible to write a self adapting application from the API:

Code:

String [] thisCode;
int i = 0;
void setup(){
thisCode = loadStrings("../adapt.pde");
String [] selfWrite = subset(thisCode,thisCode.length-4,3);
thisCode = splice(thisCode,selfWrite,thisCode.length-1);
saveStrings("adapt.pde",thisCode);
}
void draw(){
while ((++i)<thisCode.length){
println(thisCode[i]);
}
}


So can I do this from an applet? Does the applet use the .java file or is it simply there for show?

I'd very interested to hear of any alternative solutions, maybe a php hack or something. Thanks in advance.
Re: A self writing application...
Reply #1 - Sep 6th, 2005, 4:00pm
 
Applets are compiled from the java code, so unless you build a java compiler into your applet you're not going to be able to let people just input a java file.

Theoretically, you could let peolpe submite a .jar or .class file, but I've absolutely no idea how you'd go about accessing the code stored within.

Also you'd have the problem that any code anyone submitted would need to be uploaded to your webserver if you wanted anyone else to be able to see what other peopel had supplied, and to let them interact, and that would also leave the system open to abuse, someone could theoretically write code that makes the applet crash then no one will be able to see anything.

So in effect, it's a nice idea, but almot completely unworkable.
Re: A self writing application...
Reply #2 - Sep 7th, 2005, 12:52am
 
Hello,
I've been recently working on a way to dynamically load code within a processing sketch. It may interest you as you can create at runtime instances of compiled classes embedded in a .jar file. The only constraint is that your "host" application (main sketch) and the loaded classes share the same interface (basically a collection of methods). This can be seen as a kind of contract between the two sides.
I've gathered some basic code & documentations at the following url :
http://v3ga.net/processing/Dev/Plugin/

Unfortunately, this only works offline , I haven't tried it but I think it would be possible to load code from the net also.
Exporting this in an applet triggers security problems. There might be also path problems ...

Hope this helps !

Re: A self writing application...
Reply #3 - Sep 7th, 2005, 6:48am
 
though what you're doing there, i think can just be done with Class.forName() which will prevent you from needing to have your own class loader (which is what's causing the security exceptions). check out the p5 source which makes plenty of use for this when launching applets (see PApplet.main()) or loading the various graphics libs (inside PApplet.size()).
Re: A self writing application...
Reply #4 - Sep 7th, 2005, 10:08am
 
I'm definitively going to look into that direction.
Thanks Ben.
Re: A self writing application...
Reply #5 - Sep 7th, 2005, 2:32pm
 
I tried making putting together a script that Processing could turn into a .jar for me (myClass extends IPlugin) but I can't get the contents. Something  funny happens to the name of things as it gets packaged. I tried the Blah extends PApplet approach and it point blank refused to export anything. I assume I have to use an external editor to package the .jar stuff. This unfortunately goes against the whole spirit of the operation. My target was an audience of IQ 100 and below (my level). To date I've programmed exclusively in Processing and tried only some very basic notions in other languages. I looked at the advice concerning making your own libraries and that went over my head too. It took me at least 48 hours straight to sign an applet last year. I've downloaded Eclipse and it makes absolutely no sense what so ever. This is swift becoming more effort than I envisioned. Back to the drawing board I suppose...
Page Index Toggle Pages: 1