Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jython as in-game console for java game

I love both python and java and I'd love to have console in my game powered by python (jython). Handling input-output from PythonInterpreter is amazingly easy.

But right now, I need to access instance of my java application from jython. Can anyone point me to some article?

I need access to already existing instances created by java, not just classes (and creating instances in jython) as articles I found described.

like image 209
Ficik Avatar asked Jun 08 '26 04:06

Ficik


1 Answers

From the Jython docs:

http://www.jython.org/archive/21/docs/usejava.html

If you already have Jython setup, it should be as trivial as shown in the documentation to access Java Instances as they are treated as Python objects in the Jython environment.

Here's a use case in embeding Python and Java into a single jar:

http://fiji.sc/wiki/index.php/Jython_Scripting#Distributing_jython_scripts_in_a_.jar_file

and finally, from Python's tutorial:

http://www.jython.org/jythonbook/en/1.0/JythonAndJavaIntegration.html

Also make sure you understand what 'already existing instances' means vs classes. Any class you're interacting with, already exists. If you meant creating new Java objects from within Jython, that shouldn't be a problem as there is almost no interfacing code required from Python's point of view (though a bit more from Java's to create Python objects).

Good luck with your game console and hopefully the links will fill in the blanks you had about using Jython.

like image 183
Pyrce Avatar answered Jun 10 '26 08:06

Pyrce



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!