Search code examples
luaparadigms

Under which Programming Paradigm Lua can be used?


I've done some research about Lua programming but I'm still confused about under which paradigm it can work.

In some walkthroughs, I've found that Lua is not made for Object-Oriented Programming. But they are other people that says it can work too for OOP. So, I'm looking in which programming paradigms it can work the best.


Solution

  • Lua is an imperative language; so it is not ideal for functional programming.

    Left by itself, Lua is a procedural language. However, given the simplicity of its data structures (it just has one: the table) it's very easy to add a "layer" on top of it and make it an object oriented language. The most basic inheritance rule can be achieved in as little as 10 lines of code. There are several libraries out there that provide a more refined experience though. My library, middleclass, is 140 LOC in total.

    Another great way of using Lua is as an scripting language. It's small, fast, uses only standard C stuff, and it's standard lib is tiny. On the other hand, it doesn't come with "batteries included" like java does.

    Finally, I find it very useful as a data notation language; you can express raw data in a format very similar to JSON.

    In general, I think that Lua feels very close to javascript.