DEV Community

Cover image for Hello World in Lua
≀Paulo Portela
≀Paulo Portela

Posted on • Edited on

Hello World in Lua

Introduction

Imagine Lua as a versatile toolbox, perfect for tasks ranging from building games to tinkering with small gadgets. Every Lua journey starts with a simple tradition: the "Hello World" program. In this article, we'll delve into Lua's world by creating the classic "Hello World" program, understanding its syntax, and appreciating its role as the gateway to Lua mastery.

Index

  • What is Lua?
  • Setting Up Lua
  • Writing the "Hello World" Program
  • Running the Program
  • Conclusion

What is Lua?

Lua stands out as a powerful, efficient, and lightweight scripting language. It's like a chameleon, adapting to various tasks effortlessly. Lua doesn't tie you down with rigid rules; instead, it embraces flexibility. Whether you're into procedural, functional, or object-oriented programming, Lua has you covered.

Setting Up Lua

Before we jump into coding our "Hello World" masterpiece, let's make sure Lua is snugly settled on our system. You can grab Lua from the official website: lua.org/download.html. Follow the installation guide tailored for your operating system, and you're all set.

Writing the "Hello World" Program

Now that Lua is cozy on our machine, it's time to give birth to our first Lua creation. Fire up your preferred text editor and craft a new file named hello.lua. Inside this file, sprinkle the following incantation:

-- hello.lua
print("Hello, world!")
Enter fullscreen mode Exit fullscreen mode

In Lua, print() acts as a magical conduit to the console, whispering messages like "Hello, world!" into existence.

Running the Program

To witness the magic of our Lua spell, summon your terminal or command prompt. Navigate to the enchanted directory where hello.lua resides and chant the following command:

lua hello.lua
Enter fullscreen mode Exit fullscreen mode

If Lua hears your call and is properly attuned, you'll be greeted with the enchanting words:

Hello, world!
Enter fullscreen mode Exit fullscreen mode

Congratulations! You've initiated your Lua adventure with a triumphant "Hello, world!"

Conclusion

In this enchanted journey, we've unveiled Lua's charm as a nimble scripting language and embarked on the ritual of creating the timeless "Hello World" program. This humble script serves as your guiding star, illuminating the path to Lua mastery. May your Lua adventures be filled with joyous coding!

Top comments (1)

Collapse
 
ddebajyati profile image
Debajyati Dey

I would also like to learn lua someday and use it to make some a neovim plugin.