This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
DennisLysenko's profile picture

Java in ComputerCraft?

Started by DennisLysenko, 07 July 2016 - 12:16 AM
DennisLysenko #1
Posted 07 July 2016 - 02:16 AM
Can you make it where you can ALSO use Java in ComputerCraft? That wouldn't be so hard because when you run computer files that are in java, the mod can compile the code, and run it? But then that would include you having to create a Java Library or API for Java so then we could create programs. I just like the classes and objects more than Lua.
ebernerd #2
Posted 08 July 2016 - 05:27 PM
I doubt this would get any support. The whole backbone of CC (the OS, and all that) is in Lua, so a whole new CraftOS would have to be made explicitly for Java.
The Crazy Phoenix #3
Posted 08 July 2016 - 05:29 PM
Additionally, the Java APIs are more vast and much harder to sandbox.
MKlegoman357 #4
Posted 08 July 2016 - 05:40 PM
There's this.
sci4me #5
Posted 09 July 2016 - 12:37 AM
Yeah, there's NO WAY this could be added to CC. It would be quite difficult to properly sandbox Java to run in CC. Additionally, I doubt CC will ever have native support for any language besides Lua. You can always use JVML-JIT.

If you want to write your CC stuff in another language, use/write a compiler that compiles that language to Lua. Or if you don't care about speed, write an interpreter for it.
NanoBob #6
Posted 10 July 2016 - 04:56 PM
I just like the classes and objects more than Lua.
You can also do OO programming in lua.
https://www.lua.org/pil/16.html
EtK2000 #7
Posted 25 September 2016 - 08:21 AM
It's actually quite easy to sandbox Java.
You can use a custom ClassLoader and some reflection.

But this seems unfeasible, as there isn't much demand for it, and Lua works fine.
HaddockDev #8
Posted 04 October 2016 - 12:14 AM
There's already something for this in LuaJ.
If you peek around in the jar file, LuaJ is embedded in the jar.
CC uses LuaJ to handle Lua. That has a adaptation of luajava.
So, if I am correct, there is already support for Java in CC already, but Dan hasn't implemented it yet.

Sources: The LuaJ docs.
Bomb Bloke #9
Posted 04 October 2016 - 03:58 AM
Well no, not exactly. Without LuaJava the support just isn't there.
HaddockDev #10
Posted 04 October 2016 - 11:24 AM
Well, the classes are there for me.

It should just be a matter of just putting it in the standard globals for CC.
Or, if you really want to sandbox it, it might take a little while if you need to limit some standard Java APIs, like JFrame and others.
I really doubt you'd be able to sandbox though.
Bomb Bloke #11
Posted 04 October 2016 - 12:38 PM
Ah. My bad, then. :lol:/>

You've pegged the likely reason it's disabled, though - sandboxing it to the point where you could only use it within the confines of a single ComputerCraft "computer" (as opposed to, say, getting it to perform operations on the system running the Minecraft server) sounds like more trouble than it's worth.
EveryOS #12
Posted 04 October 2016 - 02:44 PM
javamod.runJava('public class main(args[]) setluavar('k', 5) blah blah blah

would be cool
apemanzilla #13
Posted 04 October 2016 - 02:55 PM
javamod.runJava('public class main(args[]) setluavar('k', 5) blah blah blah

would be cool

That's not how any of this works… You wouldn't be writing Java. You would be writing Lua that accesses and uses the Java standard libraries. Otherwise you'd need to include a Java compiler in the CC distribution and things would get even hairier…
HaddockDev #14
Posted 04 October 2016 - 08:22 PM
It is a somewhat good idea, but it comes with its pros and cons. If you are running a server, this could be really
isn't a good idea. Unless you find a way to sandbox the Java to the single computer, malicious code could be run to
bring down the server or even destroy important files. You can even crash a computer with the right code.

Could be useful, but to be honest it isn't really a good idea.