Jump to content




Java in ComputerCraft?


13 replies to this topic

#1 DennisLysenko

  • New Members
  • 1 posts

Posted 07 July 2016 - 01: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.

#2 ebernerd

  • Members
  • 262 posts
  • LocationBoston, MA

Posted 08 July 2016 - 04: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.

#3 The Crazy Phoenix

  • Members
  • 136 posts
  • LocationProbably within 2 metres of my laptop.

Posted 08 July 2016 - 04:29 PM

Additionally, the Java APIs are more vast and much harder to sandbox.

#4 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 08 July 2016 - 04:40 PM

There's this.

#5 sci4me

  • Members
  • 225 posts
  • LocationEarth

Posted 08 July 2016 - 11:37 PM

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.

#6 NanoBob

  • Members
  • 102 posts

Posted 10 July 2016 - 03:56 PM

View PostDennisLysenko, on 07 July 2016 - 01:16 AM, said:

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

#7 EtK2000

  • Members
  • 3 posts
  • LocationAs long as I have a computer, I don't care.

Posted 25 September 2016 - 07: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.

#8 HaddockDev

  • Members
  • 61 posts
  • LocationSomewhere, deep down under a rainbow.

Posted 03 October 2016 - 11:14 PM

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.

#9 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 04 October 2016 - 02:58 AM

Well no, not exactly. Without LuaJava the support just isn't there.

#10 HaddockDev

  • Members
  • 61 posts
  • LocationSomewhere, deep down under a rainbow.

Posted 04 October 2016 - 10: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.

#11 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 04 October 2016 - 11:38 AM

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.

#12 EveryOS

  • Members
  • 570 posts
  • LocationOver there ->

Posted 04 October 2016 - 01:44 PM

javamod.runJava('public class main(args[]) setluavar('k', 5) blah blah blah

would be cool

#13 apemanzilla

  • Members
  • 1,421 posts

Posted 04 October 2016 - 01:55 PM

View PostEveryOScrisp5dollarBill, on 04 October 2016 - 01:44 PM, said:

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...

#14 HaddockDev

  • Members
  • 61 posts
  • LocationSomewhere, deep down under a rainbow.

Posted 04 October 2016 - 07: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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users