Gui Heurich
4 min readMay 6, 2019

LuaBuzz: exploring a new programming language

The initial four weeks of my coding course at Makers Academy focused solely on Ruby and had a neat progression. Every week, we added a new layer. Starting with testing frameworks and building the House of TDD first, then adding web frameworks such as Sinatra (and testing with Capybara), and finally attaching a database to underpin all of this, it felt like we were close to building wholesome programs. By the end of week four, I really felt that my knowledge of Ruby had grown quite a lot.

But then, suddenly, week 5 came and JavaScript came with it. For a couple of days, it seemed that whatever I had learned during the first four weeks was out the window.

The week started with a group conversation about how could we transfer our knowledge of Ruby into learning JavaScript. Could we perhaps list everything we know about Ruby and simply translate it into JavaScript? Is there anything that, perhaps, seems impossible to translate between these two languages? In other words, do they each have unique and untranslatable quirks? These are all interesting questions — or rather pointers — that we should take with us while learning a new language.

Although I have been enjoying JavaScript a lot, I’ll write about it in the future. At the beginning of the week, our coaches at Makers challenged us to learn an additional language apart from JS and so, on Friday, I time-boxed an hour to do the classic ~FizzBuzz~ exercise in a language that I had never seen before. The task was simple: install and compile the language, write a simple program that runs smoothly, and push everything to Github in an hour.

The language I chose is Lua.

I came across Lua by doing some research on programming languages that were not written in or based on the English grammar — such as Latino or Potigol. Although most programming languages are English based, a few famous ones were developed in non-English speaking countries. Python, for example, developed in the Netherlands, and Ruby, of course, crafted in Japan. Interestingly, this Wikipedia entry also mentioned a third language along with Python and Ruby.

Lua — “Moon” in Portuguese — was created in Rio de Janeiro(Brazil) in 1993. Fast forward a couple of decades and Lua has become “THE” language for gaming: it is used in Angry Birds and is the main language behind World of Warcraft. In 2003, it was voted the most popular scripting language for game programming.

Great, but what does Lua look like and how does it work?

I installed Lua by following the instructions on www.lua.org. The compilation takes only a few moments and produces three files: lua (the interpreter), luac (the compiler), and liblua.a (the library). I opened Atom and tried to create my first .lua file, but at first, Atom didn’t recognize Lua and set the file as plain-text. That was not good and eventually I found an Atom package that provided syntax highlighting for Lua.

Next step, finding a testing framework. This, however, proved to be a bit tricky. After installing the test suite, I tried running some tests, but was a bit puzzled by the very long result. I couldn’t quite figure out, at the beginning, how to use it, and after giving it five more minutes, I decided to move on.

Lua provides a mode called interactive mode. In this mode, you can type in instructions one after the other and get instant results. This can be invoked in the shell by using lua -i or just the lua command. Although the test suite had proven to be a little hard to use, just running “lua fizzbuzz.lua” on terminal gave me interesting errors; errors that allowed me to move on.

lua: fizzbuzz.lua:5: <name> expected near ‘end’

However, once the program runs “smoothly” (granted that it doesn’t do much at this point) and you get no more error messages, you have to find a way to move on. I played around with the Lua REPL for a while and then attempted to write FizzBuzz. Since what I needed, basically, is a loop that prints out numbers, I had a brief look at this page.

It felt quite intuitive, very similar to Ruby — specially “do…end” syntax. this is what I came up with, in the end:

And here after running for the first 40 numbers.

Overall, Lua seems lightweight on syntax and feels quite intuitive. Most commands I tried worked after simple changes. In under an hour, LuaBuzz was ready and on Github.

*

At the beginning of this week, I wrote down everything I remembered about Ruby. Classes, Operators, Conditionals, REPL, Testing Suite… and tried to find an equivalent for each in JavaScript. I didn’t do the same when looking at Lua — among other things because I set myself one hour to finish FizzBuzz — but I guess this was this week’s overall lesson: if I work methodically, I can learn anything.

Gui Heurich

; anthropologist, currently learning how to code ; student at Makers, London.