DEV Community

JavaCode7
JavaCode7

Posted on • Updated on

Lua v Ruby

Lua. My 5th favourite language (after python, typescript, go and javascript). While not that powerful, it's the language of choice for roblox and some 2D gamedevs (via Love2D). Coded in C with easily readable syntax and good for beginners. Lua is going to put up a good fight.

Ruby. Not that popular in gamedev but useful in webdev (via ruby on rails) it is the language that just so happens to power DEV! Much more powerful than lua at the expense of speed and effectiveness as a first programming language for absolute beginners.

Lua

Let's see what we have here:

  • ✔  Fast
  • ✔  Game engine support
  • ✔  Simple syntax
  • ✔  Dynamically typed
  • ✔  Compiled
  • ❌ Not very powerful
  • ❌ Compiles to .out files unless you use srlua
  • ❌ Have to download the package manager.

Ruby

And rivalling lua:

  • ❌ Not as fast as lua
  • ✔  Game engine support (Ruby2D)
  • ✔  Simple syntax
  • ✔  Dynamically typed
  • ✔  Interpreted
  • ❌ Very powerful
  • ✔  Webdev
  • ✔  Built in package manager

And there we have it! Ruby wins by 1 point. This brings me to the end of my article but I would love to hear what you think! Comment down below to share your thoughts 💬.

Top comments (4)

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

So, I write both languages a lot: Lua is my language of choice at home, while Ruby is what we use at work.

Regarding Lua:

✔ Game engine support

This is misleading Lua doesn't "support" game engines any more than any other language; game engines just choose to use Lua for scripting.

✔ Compiled

This is completely wrong. Lua is an interpreted language, and even just googling it should tell you as much.

❌ Not very powerful

This is a more subjective point, and could mean lots of different things. Lua has a simpler syntax and less language features (no case statements, no continue, etc.)

But in terms of what it can do it is an extremely powerful language due to its metaprogramming capabilities, which are comparable to those of languages like JavaScript. Ruby sometimes feels a bit lacking in this regard.

❌ Compiles to .out files unless you use srlua

Pre-compiling Lua code to byte code is a rarely used optimisation option. It isn't a compilation step as known from compiled languages like C; it simply makes loading code a bit faster as the VM can simply read in the binary data instead of having to parse the text first.

❌ Have to download the package manager.

This is also slightly misleading: Lua is built to be embedded, so many of its environments will not support packages, or have their own domain-specific package system.

When using Lua as a stand-alone language, installing a package manager like Luarocks is definitely essential though, and in Ruby this comes with the language.

As for ruby:

❌ Not as fast as lua

This is relative. Ruby with YJIT enabled can run faster than interpreted Lua, and LuaJIT, which is a separate Lua runtime and a fork of the language, will generally outperform even YJIT Ruby.

Both languages implement many of their features in C libraries, which will also impact their performance, as the "slow" part of many programs won't actually happen in the language itself, but in native code.

✔ Simple syntax

While ruby has many syntax features that make it easy to write readable code, there are also plenty of pitfalls, ambiguities, etc.

Lua has a very similar syntax, but just has a lot less of it, so it is easier to get to the point where you can be presented with any Lua program, and will be able to just read it and figure out what is going on.

❌ Very powerful

I'm guessing this was meant to be a ✔? Either way, see corresponding explanation for Lua as to why this isn't really accurate.

✔ Webdev

Similar to games, this isn't much of an exclusive property of the language. Ruby has more tooling for building certain types of application back-ends, which often makes it preferable to Lua as a back-end language. But it is very much possible to write web applications in Lua, and there is several successful sites out there that use Lua for back-end logic to varying degrees; itch.io being a good example of a site that's built almost entirely using Lua.

Collapse
 
freakcdev297 profile image
FreakCdev • Edited

I don't really know what's "not powerful" or "powerful" ?

Besides, I thought Lua came with a package manager depending where you're downloading it? Mine came with... pretty much everything.

Collapse
 
javacode7 profile image
JavaCode7

I have 2. One from Lua for windows and another from MinGW. Neither came with Rocks or any other package manager.

Collapse
 
javacode7 profile image
JavaCode7

The "power" of programming language is its functionality.