Java code

Monkey Targets Forums/Android/Java code

Leonid(Posted 2013) [#1]
Tell me please.
Is it possible to embed Java code in the Code Monkey.
If so, how. Can example.


therevills(Posted 2013) [#2]
You can call external (extern) functions for all supported Monkey languages.

Have a look at Diddy's native functions file:

http://code.google.com/p/diddy/source/browse/src/diddy/externfunctions.monkey


Zurrr(Posted 2013) [#3]
This is really basic module templete that use java in android development

Create a folder in modules folder. Example "myjavacode"
Create a file in that folder name the same as folder "myjavacode.monkey"

Put this example code there:
#If TARGET="android"
	Import "native/myjavacode.${TARGET}.${LANG}"
	Extern
	Function Power:Int(VAR:Int)="myjavacode.Power"
#End
Create a folder name "native" inside "myjavacode"
Create a file in native folder name "myjavacode.android.java". This is your java code

Put this example java code:
//import com.bla.bla.*;
class myjavacode {
	public static int Power(int VAR) {
		return VAR*VAR;
	}
}
Example your "game.monkey" that use that "myjavacode" module
Import mojo
Import myjavacode     'import myjavacode
Class MyApp Extends App
	Method OnCreate()
		SetUpdateRate 60
	End
	Method OnUpdate()
 	End
	Method OnRender()
		DrawText "Call java:"+Power(12),50,50    'call myjavacode
	End
End
Function Main()
	New MyApp	
End
All done then try compile/run android


therevills(Posted 2013) [#4]
Why have you got you java class extending Activity? Were you planning on creating a new "screen" outside of Monkey?


Zurrr(Posted 2013) [#5]
ops sorry.. edited!
fyi..I'm not good in java.