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

Any way to use JS instead of Lua?

Started by Ampix0, 06 March 2016 - 06:48 PM
Ampix0 #1
Posted 06 March 2016 - 07:48 PM
Basically exactly the title.
Saldor010 #2
Posted 06 March 2016 - 08:25 PM
Not easily. However, there are some compilers on the forum that allow you to write in other languages. This is one I found after a minute of searching that appears to have similar features to JavaScript, though I'm sure there are more around the forum.

http://www.computercraft.info/forums2/index.php?/topic/25482-language-luva-v112-compiles-to-lua/
SquidDev #3
Posted 06 March 2016 - 09:13 PM
There was a Javascript to Lua compiler written a while back, but it doesn't look like it is very feature complete (for loops are not implemented for instance). There isn't a way to switch a computer to use a different language though (though someone wrote a python addon).
Ampix0 #4
Posted 07 March 2016 - 02:57 AM
The javascript to lua compiler is perfect! if it works lol. I'm hoping I can write functions.
Lupus590 #5
Posted 07 March 2016 - 11:43 AM
What is the reason that you don't want to use Lua?
Ampix0 #6
Posted 07 March 2016 - 08:54 PM
What is the reason that you don't want to use Lua?

I am learning JS currently but the real reason is LUA isn't OOP, and I really dont want to learn LUA and JS at the same time since what I would do for LUA would be VERY BAD in JS.

JS is also much cleaner and has much more functionality than LUA does (likely the reason CC uses lua).

Basically speaking I would be able to make much better programs personally in JS, and I really don't want to cloud my learning with two different approaches to programming in general. I don't want LUA to create bad practices for me in JS.
SquidDev #7
Posted 07 March 2016 - 09:32 PM
I am learning JS currently but the real reason is LUA isn't OOP, and I really dont want to learn LUA and JS at the same time since what I would do for LUA would be VERY BAD in JS.

JS is also much cleaner and has much more functionality than LUA does (likely the reason CC uses lua).

Basically speaking I would be able to make much better programs personally in JS, and I really don't want to cloud my learning with two different approaches to programming in general. I don't want LUA to create bad practices for me in JS.

I'd really recommending coming and learning Lua once you feel comfortable with JS. Its good to try different languages, and some features of Lua (such as metatables) aren't really possible in JS (and the other way round too). Lua won't teach you any bad practices but there is a bit of a style difference in the languages. Good luck!
Lupus590 #8
Posted 07 March 2016 - 10:54 PM
I am learning JS currently but the real reason is LUA isn't OOP,

yes and no, while Lua doesn't have objects it can pretend to

obj = {}
obj.x = 5

function obj:getX() --# note that we are using a colon not a dot
  return self.x --# self is the table that this function is in, the colon does some stuff in the background to give us self
end

function obj:setX(newX) --# works with parameters too
  self.x = newX
end

--# lets redefine those functions to use dots (we are going to do what Lua does for us when we used the colons above)

function obj.setX(self, newX) --# I'm going to skip the function body here as it is the same as above
  --# self could be anything but you will have to be consistent in the body of the function

--# lets call those functions

obj:setX(2) --# if we use a colon then we don't need to pass anything other than the new x value
  --# it should be noted that I can use this colon notation even if the function was defined with a dot like above

--# lets break the magic that Lua is doing again

obj.setX(obj, 2) --# this time we have to pass the table (or object) ourselves, the colon is just short hand for this
  --# once again I can use this method for both definitions
as you can see objects in Lua are a bit of a bodge which is why most people don't use them.

I really dont want to learn LUA and JS at the same time since what I would do for LUA would be VERY BAD in JS.
this is a valid reason, best of luck finding a JS-> Lua converter

also:
"Lua" (pronounced LOO-ah) means "Moon" in Portuguese. As such, it is neither an acronym nor an abbreviation, but a noun. More specifically, "Lua" is a name, the name of the Earth's moon and the name of the language. Like most names, it should be written in lower case with an initial capital, that is, "Lua". Please do not write it as "LUA", which is both ugly and confusing, because then it becomes an acronym with different meanings for different people. So, please, write "Lua" right!
http://www.lua.org/about.html
Edited on 07 March 2016 - 09:54 PM