Java ScriptEngine-Like step by step execution

Is there a way to execute a code like the ScriptEngine does, but step by step ?

For exemple :

    if (contact(player,self)){
    	callCinematics("forest.png", "face1.png","SALUT!");
    	teleport("test",0,5,5);
    } else {
    	print("A");
    }

I want to execute this code step by step, when I call my function eval(), first, it will check the condition, and wait for the second call.
If the first call return true, the second call eval the “callCinematics(…);”, or “print(“A”);” if the first call return false.
If the first call return false, the third call of eval will do nothing, until I call another function that restart all the call.

I don’t know if i’m very understandable ^^’.

No :wink:

The term you are probably searching for is “continuations“ or “coroutines“. You need a library to do that in java.

See for example http://www.java-gaming.org/topics/java-continuations-and-greenthreads/28337/view.html

Exactly, i want to use coroutine :D.

I found the Mathias Mann .jar fr making Coroutine, but it gives me error every time :

Exception in thread "main" java.lang.Error: Calling function not instrumented
	at de.matthiasmann.continuations.Coroutine.yield(Coroutine.java:77)
	at MyCoroutine$1.coExecute(MyCoroutine.java:17)
	at de.matthiasmann.continuations.Coroutine.run(Coroutine.java:164)
	at MyCoroutine.main(MyCoroutine.java:23)

:confused:

Follow the instructions, or use my library that does the work for you.

I already try, and I get this error :

java.lang.NoClassDefFoundError: org/objectweb/asm/ClassWriter
	at java.lang.Class.getDeclaredMethods0(Native Method)
	at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
	at java.lang.Class.getDeclaredMethod(Unknown Source)
	at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(Unknown Source)
	at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.ClassWriter
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	... 5 more
FATAL ERROR in native method: processing of -javaagent failed
Exception in thread "main" 

I’m using Eclipse, so in Run Configurations, I add -javaagent:continuations-agent.jar in VM Arguments.
But it doesn’t work :confused:

Add ASM to the classpath.

[Continuations] ERROR: Unable to instrument
java.lang.IllegalArgumentException
	at org.objectweb.asm.ClassReader.<init>(ClassReader.java:170)
	at org.objectweb.asm.ClassReader.<init>(ClassReader.java:153)
	at org.objectweb.asm.ClassReader.<init>(ClassReader.java:424)
	at de.matthiasmann.continuations.instrument.MethodDatabase.extractSuperClass(MethodDatabase.java:308)
	at de.matthiasmann.continuations.instrument.MethodDatabase.getDirectSuperClass(MethodDatabase.java:350)
	at de.matthiasmann.continuations.instrument.MethodDatabase.getSuperClasses(MethodDatabase.java:330)
	at de.matthiasmann.continuations.instrument.MethodDatabase.getCommonSuperClass(MethodDatabase.java:225)
	at de.matthiasmann.continuations.instrument.DBClassWriter.getCommonSuperClass(DBClassWriter.java:50)
	at org.objectweb.asm.ClassWriter.getMergedType(ClassWriter.java:1571)
	at org.objectweb.asm.Frame.merge(Frame.java:1424)
	at org.objectweb.asm.Frame.merge(Frame.java:1352)
	at org.objectweb.asm.MethodWriter.visitMaxs(MethodWriter.java:1303)
	at de.matthiasmann.continuations.instrument.InstrumentMethod.accept(InstrumentMethod.java:238)
	at de.matthiasmann.continuations.instrument.InstrumentClass.visitEnd(InstrumentClass.java:132)
	at org.objectweb.asm.ClassReader.accept(ClassReader.java:673)
	at org.objectweb.asm.ClassReader.accept(ClassReader.java:506)
	at de.matthiasmann.continuations.instrument.JavaAgent.instrumentClass(JavaAgent.java:134)
	at de.matthiasmann.continuations.instrument.JavaAgent$Transformer.transform(JavaAgent.java:160)
	at sun.instrument.TransformerManager.transform(Unknown Source)
	at sun.instrument.InstrumentationImpl.transform(Unknown Source)
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(Unknown Source)
	at java.security.SecureClassLoader.defineClass(Unknown Source)
	at java.net.URLClassLoader.defineClass(Unknown Source)
	at java.net.URLClassLoader.access$100(Unknown Source)
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at MyCoroutine.main(MyCoroutine.java:22)
[Continuations] ERROR: Unable to instrument
java.lang.IllegalArgumentException
	at org.objectweb.asm.ClassReader.<init>(ClassReader.java:170)
	at org.objectweb.asm.ClassReader.<init>(ClassReader.java:153)
	at org.objectweb.asm.ClassReader.<init>(ClassReader.java:424)
	at de.matthiasmann.continuations.instrument.MethodDatabase.extractSuperClass(MethodDatabase.java:308)
	at de.matthiasmann.continuations.instrument.MethodDatabase.getDirectSuperClass(MethodDatabase.java:350)
	at de.matthiasmann.continuations.instrument.MethodDatabase.getSuperClasses(MethodDatabase.java:330)
	at de.matthiasmann.continuations.instrument.MethodDatabase.getCommonSuperClass(MethodDatabase.java:225)
	at de.matthiasmann.continuations.instrument.DBClassWriter.getCommonSuperClass(DBClassWriter.java:50)
	at org.objectweb.asm.ClassWriter.getMergedType(ClassWriter.java:1571)
	at org.objectweb.asm.Frame.merge(Frame.java:1424)
	at org.objectweb.asm.Frame.merge(Frame.java:1352)
	at org.objectweb.asm.MethodWriter.visitMaxs(MethodWriter.java:1303)
	at de.matthiasmann.continuations.instrument.InstrumentMethod.accept(InstrumentMethod.java:238)
	at de.matthiasmann.continuations.instrument.InstrumentClass.visitEnd(InstrumentClass.java:132)
	at org.objectweb.asm.ClassReader.accept(ClassReader.java:673)
	at org.objectweb.asm.ClassReader.accept(ClassReader.java:506)
	at de.matthiasmann.continuations.instrument.JavaAgent.instrumentClass(JavaAgent.java:134)
	at de.matthiasmann.continuations.instrument.JavaAgent$Transformer.transform(JavaAgent.java:160)
	at sun.instrument.TransformerManager.transform(Unknown Source)
	at sun.instrument.InstrumentationImpl.transform(Unknown Source)
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(Unknown Source)
	at java.security.SecureClassLoader.defineClass(Unknown Source)
	at java.net.URLClassLoader.defineClass(Unknown Source)
	at java.net.URLClassLoader.access$100(Unknown Source)
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(Unknown Source)
	at java.security.SecureClassLoader.defineClass(Unknown Source)
	at java.net.URLClassLoader.defineClass(Unknown Source)
	at java.net.URLClassLoader.access$100(Unknown Source)
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at MyCoroutine.main(MyCoroutine.java:22)
[Continuations] ERROR: Unable to instrument
java.lang.IllegalArgumentException
	at org.objectweb.asm.ClassReader.<init>(ClassReader.java:170)
	at org.objectweb.asm.ClassReader.<init>(ClassReader.java:153)
	at org.objectweb.asm.ClassReader.<init>(ClassReader.java:424)
	at de.matthiasmann.continuations.instrument.MethodDatabase.extractSuperClass(MethodDatabase.java:308)
	at de.matthiasmann.continuations.instrument.MethodDatabase.getDirectSuperClass(MethodDatabase.java:350)
	at de.matthiasmann.continuations.instrument.MethodDatabase.getSuperClasses(MethodDatabase.java:330)
	at de.matthiasmann.continuations.instrument.MethodDatabase.getCommonSuperClass(MethodDatabase.java:225)
	at de.matthiasmann.continuations.instrument.DBClassWriter.getCommonSuperClass(DBClassWriter.java:50)
	at org.objectweb.asm.ClassWriter.getMergedType(ClassWriter.java:1571)
	at org.objectweb.asm.Frame.merge(Frame.java:1424)
	at org.objectweb.asm.Frame.merge(Frame.java:1352)
	at org.objectweb.asm.MethodWriter.visitMaxs(MethodWriter.java:1303)
	at de.matthiasmann.continuations.instrument.InstrumentMethod.accept(InstrumentMethod.java:238)
	at de.matthiasmann.continuations.instrument.InstrumentClass.visitEnd(InstrumentClass.java:132)
	at org.objectweb.asm.ClassReader.accept(ClassReader.java:673)
	at org.objectweb.asm.ClassReader.accept(ClassReader.java:506)
	at de.matthiasmann.continuations.instrument.JavaAgent.instrumentClass(JavaAgent.java:134)
	at de.matthiasmann.continuations.instrument.JavaAgent$Transformer.transform(JavaAgent.java:160)
	at sun.instrument.TransformerManager.transform(Unknown Source)
	at sun.instrument.InstrumentationImpl.transform(Unknown Source)
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(Unknown Source)
	at java.security.SecureClassLoader.defineClass(Unknown Source)
	at java.net.URLClassLoader.defineClass(Unknown Source)
	at java.net.URLClassLoader.access$100(Unknown Source)
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at de.matthiasmann.continuations.CoIterator.<init>(CoIterator.java:51)
	at MyCoroutine$YieldReturn.<init>(MyCoroutine.java:7)
	at MyCoroutine.main(MyCoroutine.java:22)
Exception in thread "main" java.lang.Error: Calling function not instrumented
	at de.matthiasmann.continuations.Coroutine.yield(Coroutine.java:77)
	at de.matthiasmann.continuations.CoIterator.produce(CoIterator.java:91)
	at MyCoroutine$YieldReturn.run(MyCoroutine.java:11)
	at de.matthiasmann.continuations.CoIterator$DelegateExecute.coExecute(CoIterator.java:114)
	at de.matthiasmann.continuations.Coroutine.run(Coroutine.java:164)
	at de.matthiasmann.continuations.CoIterator.hasNext(CoIterator.java:56)
	at MyCoroutine.main(MyCoroutine.java:23)

:confused: