What is Lua?

We’ll cover the following

  • What is Lua?
  • What is Lua used for?
  • Is Lua faster than Python?
  • Lua vs Python
  • Lua Basics Tutorial
  • How do tables work in Lua?
  • How to use C or C++ with Lua

Lua is a lightweight dynamic scripting language often embedded into other programs like World of Warcraft and Roblox. It’s minimal syntax makes it easier to learn than Python, while being much more performant than other interpreted languages.

What is Lua?

Lua a fast multi-paradigm scripting language famous for being so underrated imagine a language that’s easier to learn than python while also being faster and more portable than python. lua was named after the moon when it was designed by a team of computer scientists in brazil in 1993 it’s lightweight and and extremely fast because its virtual machine maps very closely to c and when used with its just-in-time compiler it’s widely considered the fastest scripting language in the world.

What is Lua used for?

This makes it ideal for embedding into other applications like World of Warcraft or Roblox for example where users can write lua to build their own games and features because the language is embedded into the base game it’s easy to learn because it has only 21 reserved words and has only one data structuring mechanism called a table that can represent arrays dictionaries graphs trees and more it also supports collaborative multitasking with co-routines its standard library is very minimal but it does have a large ecosystem of packages with the lua rocks package manager to get started install it then create a file ending in.

Lua Basics Tutorial

Lua declare a variable by providing a name of a value by default variables are global but make them local with the local keyword it’s a dynamic language so no type annotations
are required we can then use print to output the value to the standard output. There are no classes in lua but anything you can imagine can be done with functions and tables.

A function is declared with the function keyword then closed with end keyword functions are first class objects which means they can be passed around to other functions to support functional programming patterns now to structure data you create tables with braces a table is actually an associative array which means the index in the array can be replaced with different values by default it uses integer values and the craziest thing about this language
is that it starts the index at 1 instead of 0 like most languages that gives us a conventional array but we can also easily create a dictionary by giving the keys a string value now we can use for loop over every key value pair.

How to use C or C++ with Lua

In the table the language is single threaded but we can use coroutines to pause and resume a function create a co-routine then use yield to suspend its execution now somewhere else in the code use co-routine resume to continue execution until you get to the return statement now if you are a c programmer you will be happy to know that lua has a very simple c api it allows us to run lua code inside a c program or vice versa run c code from a lua program now to execute your code open up the terminal and run the lua interpreter.

🔗 Resources

Lua Manual https://www.lua.org/manual/5.3/manual.html

Lua History https://www.researchgate.net/publicat…

Lua C API https://riptutorial.com/lua/topic/671…

That’s it!
You have successfully completed the post. Do Share : )

Peace Out!

Check Out Deals on -> Amazon , Flipkart , Myntra , Adidas , Apple TV , Boat , Canva , Beardo , Coursera , Cleartrip , Fiverr , MamaEarth , Swiggy, KFC

Leave a Reply

Your email address will not be published.