1 posts
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
1522 posts
Location
The Netherlands
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.
799 posts
Location
Land of Meh
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.
1522 posts
Location
The Netherlands
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!