5 reasons you should learn Lua
Tags: lua
Published: 2018-12-14 17:37:32

---
title: 5 reasons you should learn Lua
published: true
description: Learning Lua for developers
tags: lua
---

If you haven't heard of [Lua](https://www.lua.org/), it's a really small programming language. Maybe you have heard of it, but never had a reason to learn it because your programming language of choice does everything you need it to. Well, here are a few reasons you should learn Lua anyway.

## 5.

Have you heard/used [nginx](https://www.nginx.com/)? You can use mini Lua scripts inside of nginx with the [openresty setup](https://github.com/openresty/lua-nginx-module). This would allow you to do things like dynamically assign SSL certs through Let's Encrypt to different domains.

```lua
auto_ssl:set("allow_domain", function(domain)
  return ngx.re.match(domain, "^(mysite.com|yoursite.com)$", "ijo")
end)
```

Use Apahce instead of nginx? Lua still has you [covered](http://httpd.apache.org/docs/trunk/developer/lua.html).

## 4.

Another popular tool that is used in the web is [Redis](https://redis.io/). If you use redis to store lists of timeline event IDs or something, you may need to do some crazy sorting on this data. Writing `RPOPLPUSH` statements in redis can get a little crazy, and sometimes the language you choose may not be as fast as you'd like. For example, if you're using ruby, there's a gem called [Wolverine](https://github.com/Shopify/wolverine). You write a Lua script that does all the crazy sorting you need, and then pass that data back to your rails app. This gives you a massive performance boost.

## 3.

If you need lots of performance for your web app, but you don't have the capacity to re-write in something different, then you may employ heavy cache in to your app. One way to do this is to throw [Varnish](http://varnish-cache.org/) in front of your app. Varnish will handle all the cache, and only proxy back to your app when the cache is expired. 

Varnish uses these vcl scripts which can get a little confusing. With a little [lua magic](https://github.com/flygoast/libvmod-lua) you can write some nice programmatic cacheing. Maybe cache different lengths based on the domain in a multi-tenant situation? 

## 2.

Are you big in to playing video games? Maybe you've heard of some of these?
* Angry Birds
* Civilization V
* Far Cry
* Garry's Mod
* Heroes of Might and Magic V
* L.A. Noire
* Mafia II
* Roblox
* Saints Row 2
* SimCity 4
* Star Wars Battlefront 
* Stepmania
* Warhammer
* World of Warcraft

All of these games use Lua in some capacity, and there's MANY more. Most games or game engines will be written in C++ or C#, but using Lua on the front end for scripting allows for rapid development of these games. No need to re-compile each time. Compile your engine, and have it run the lua scripts. You can get started with [Love2d](https://love2d.org/) or [defold](https://www.defold.com)

## 1.

Because Lua is fun to write! If you don't know it, it wouldn't hurt to learn a new language. If you already know how to program, picking up lua should be pretty quick. Read over this [15 min of lua](http://tylerneylon.com/a/learn-lua/), and you will have a decent understanding of the syntax. At that point it's just a matter of digging in!