cat /dev/brain |

Using a lua for great power and good

published on Friday, February 3, 2017

I love lua for so many reasons: For one, it aims to be different. And then, it helps us stay in shape by making simple tasks more challenging and keeping us attentive. This is not just yet another language, in lua we have (no particular order):

It's quick, it's clean, and it's pure.

Go lua!

Yet another name for NULL

God spoke: Every language shalt have their own slightly different NULL thingy.

And so it was:

  • C: NULL
  • C++: nullptr
  • perl: undef
  • python: None
  • javascript: undefined / null
  • lua: nil

Great error-safety!

Tired of converting strings to numbers?

> "1" + "2"
3.0

Tired of remembering the correct number of function arguments? Lua has your back:

> x = function (a) print(a) end
> x()
nil
> x(1, 2)
1

Tired of getting exceptions when accessing non-existent entries? No more worries:

> t = {foo="foo"}
> w = {t.foo, t.bar, t["baz"], t[qux]}
> print(unpack(w))
foo

Tired of keeping track of variable names? Need automatic spelling correction? Lua does it for you (but for now it works only for variables refering to nil values):

> complicated = nil
> print(coplimated)
nil

To be fair

Most of the above applause is not specific to lua. In many regards, lua is very similar to javascript and perl.

And I do get, why certain things are the way they are. Lua is supposed to be a simple, lightweight and portable scripting language that is easy to embed in arbitrary applications.

And there are neat things about the language too: In fact, I (kind of) do enjoy the simplicity and differentness of the prototype based object orientation.

For a more comprehensive list, see Lua Gotchas.

This entry was tagged lua, quirks and wat