Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

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 namedhello.lua. Inside this file, sprinkle the following incantation:

-- hello.luaprint("Hello, world!")
Enter fullscreen modeExit 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 wherehello.lua resides and chant the following command:

lua hello.lua
Enter fullscreen modeExit fullscreen mode

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

Hello, world!
Enter fullscreen modeExit 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)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
ddebajyati profile image
Debajyati Dey
Web Developer, Linux enthusiast, always eager to learn new technologies
  • Location
    West Bengal, India
  • Education
    Maulana Abul Kalam Azad University of Technology, W.B.
  • Pronouns
    He/Him
  • Joined

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

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

  • Location
    Portugal
  • Education
    ISEP
  • Work
    Senior Software Developer @ adidas
  • Joined

More from≀Paulo Portela

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp