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

How to run JavaScript in ComputerCraft

Started by Pirschjager, 03 May 2013 - 03:02 PM
Pirschjager #1
Posted 03 May 2013 - 05:02 PM
Title: How to run JavaScript in ComputerCraft

People are getting other languages running on ComputerCraft computers.
I'd like to explore the possibility of executing JavaScript code (not Java, Lua, or anything else) on computers in-game.

Thanks!
Pirschjager
Engineer #2
Posted 03 May 2013 - 06:19 PM
You need to code your own interpreter in lua. As far as I searched no-one did make it yet.
GravityScore #3
Posted 04 May 2013 - 11:49 AM
Just to expand on what Engineer said:

This isn't possible (well, isn't possible without an extreme amount of work) currently. This is because Lua and JavaScript are very different languages in terms of how they're structured syntactically, and how they're run. Lua is a C based language (this basically means that a program written in C converts Lua code into C, then executes it - a program that does this is called an interpreter), and can easily be executed from within C (or any C variant) code. There's also a very handy Java library called LuaJ which allows you to run Lua from within Java (which is how CC can exist).

To execute JavaScript from CC easily would require the mod's developers to completely rewrite the code execution method present in the mod to accomodate for a completely different library that is able to execute JavaScript from within Java. This is also not possible in Lua without you writing an interpreter (something that would convert JavaScript code into Lua code), which would be really hard to do.
Engineer #4
Posted 04 May 2013 - 11:53 AM
Just to expand on what Engineer said:

This isn't possible (well, isn't possible without an extreme amount of work) currently. This is because Lua and JavaScript are very different languages in terms of how they're structured syntactically, and how they're run. Lua is a C based language (this basically means that a program written in C converts Lua code into C, then executes it - a program that does this is called an interpreter), and can easily be executed from within C (or any C variant) code. There's also a very handy Java library called LuaJ which allows you to run Lua from within Java (which is how CC can exist).

To execute JavaScript from CC easily would require the mod's developers to completely rewrite the code execution method present in the mod to accomodate for a completely different library that is able to execute JavaScript from within Java. This is also not possible in Lua without you writing an interpreter (something that would convert JavaScript code into Lua code), which would be really hard to do.

I should explain it more in the future (Im always presuming that the OP knows as much as I do) . Thanks that you have given the explanation!