Students are given an account at code.org. As such students are provided with an opportunity to learn coding at their own pace, and promote SDL (student directed learning)
In this article, we'll cover the basics of the Lua programming language, including:
What it is
Main components
Key features
Pros & cons
Use cases
Lua vs other languages
Installing Lua in a Windows environment
Getting it up and running
Let's get started.
What is Lua?
Lua is a robust, lightweight, and embeddable scripting language that supports multiple programming methods, including procedural, object-oriented, functional, and data-driven programming.
As the primary focus on Lua is for scripting, it is rarely used as a standalone programming language. Instead, it is used as a scripting language that can be integrated (embedded) into other programs written in mainly C and C++. It also supports other programming languages via third-party plugins (NLua/KeraLua for .NET/C#).
Popular use cases for Lua include:
As a popular component in video game and game engine development. For example, Warframe, World of Warcraft, and CRYENGINE all use Lua.
As a programming language in many network programs, like CISCO Systems, Nmap, and ModSecurity.
As a programming language in industrial programs such as Adobe Lightroom and MySQL Workbench.
As a library that developers can integrate with their programs to enable scripting functionality.
Being a scripting language, Lua does not have its own main application. Instead, it acts exclusively as an embedded part of the host application.
Lua is not directly interpreted through a Lua file like other languages such as Python. Instead, it uses the Lua interpreter to compile a Lua file to bytecode. The Lua interpreter is written in ANSI C, making it highly portable and capable of running on a multitude of devices.
Usually, the compilation is done at the runtime. However, sometimes it can be done before the runtime to increase load times. Then the Lua virtual machine will run this compiled bytecode. The register-based architecture of the Lua virtual machine closely resembles actual hardware architectures, and it will increase the overall performance of the program.
Key features of Lua
So, what's so great about Lua? These are the defining features:
Speed
Lua is considered one of the fastest programming languages among interpreted scripting languages. In particular, Lua can perform large task orders faster than most other programming languages in both benchmarking and real-world scenarios.
For more speed, an independent implementation of Lua called LuaJIT uses a just-in-time compiler that makes Lua even faster.
Size
Lua has a considerably smaller footprint than other programming languages, with its complete source code and documentation taking a mere 1.3 MB. The Lua interpreter with all the standard libraries takes 278K, while the complete Lua library takes only 466K.
This small size is ideal when integrating Lua into multiple platforms, from embedded devices to massive game engines, where every byte is valuable.
Portability & embeddability
With its small size, the portability of Lua is nearly unlimited; any platform that supports the standard C compiler can run Lua out of the box. Lua's speed and size become huge advantages when embedding Lua with another programming language. That's because they can help increase the speed of the program without hindering any existing functionality.
Importantly, Lua does not require complex rewrites to be compatible with other programming languages. Lua can be used with primary programming languages like C, C++, Java, C#, etc.. and other scripting languages like Perl and Ruby, further extending its usability.
Simplicity
Lua is simple in design yet provides powerful functionality. One of the core features of Lua is meta-mechanisms which enable developers to implement features—rather than providing a bunch of features directly in the language itself.
Lua also comes with incremental garbage collection, reducing memory usage and implementation complexity. Its sandboxing feature can be used to isolate functions and resources. This increases the security of the program and provides coroutines for multitasking.
All these features come with a simple syntax and easily understandable format so that anyone can easily pick up Lua and use it in their programs.
License
Lua is free and open-source software distributed under the MIT license. This means anyone can use Lua for any purpose without paying any licensing or royalty fees.
Advantages & drawbacks
Like any language, Lua has its pros and cons.
Advantages of Lua
Easy app integration. Its high performance and small size make it easy to integrate Lua into applications.
Simple syntax. Relatively simple syntax structure with around 20 dedicated keywords, which helps to dive into Lua programming easily.
Flexibility. Without standard libraries, you can customize Lua to meet any need.
Cross-platform compatibility and support for the standard C compiler allows Lua to run virtually anywhere.
Dynamic variables in Lua allow defining variables without defining types, and the type is determined automatically at the runtime.
Easy debugging. Simple and powerful debug library.
Plenty of documentation. Comprehensive documentation to get Lua projects up and running quickly and the active community.
Disadvantages of Lua
Limited error handling support can lead to longer debug times to identify the exact errors in a Lua script.
All variables are created as global variables (global scope), which can lead to errors in variable assignments.
Limited pattern matching support.
When to use Lua
As a scripting language without major limitations, you can use Lua for any scenario, from a simple backend script in a web server to complex game development.
Lua is highly prevalent in video game development as it can be used to create functionality without contaminating the overall performance while also keeping everything separate.
Another area that Lua excels is embedded programming, where size and performance are major concerns. Lua can be used in everyday applications to extend the existing functionality or create new features and functions.
Some popular games, programs, and services that use Lua are Dark Souls, Fable II, Garry's Mod, Wireshark, VLC, Apache, and Nginx Web Servers.
Lua vs other languages
How does Lua stack up against other languages?
Here's a look at the differences between the high-level general programming language Python, the high-level object-oriented Java, and web-focused Javascript—all compared to Lua.
Installing Lua
Now, let's see how to set up a development environment in Windows. First, we'll install Lua.
Step 1
Navigate to the Lua.org download page. Here, we will be using a precompiled binary to install Lua in windows. So, click on "get a binary link" as shown in the below screenshot.
Step 2
Click "Download" on the LuaBinaries page, and you will be redirected to a page with a list of precompiled binaries. Select the appropriate version from that list.
We will be using the latest Lua version for Windows 64 bit.
This will direct the user to a SourceForge page, where the binary will be downloaded.
Step 3
Move the downloaded Zip file to any location to store the binaries permanently.
Here, we will be using the "D:\Program Files\Lua" as the location. After moving the Zip file, simply extract its content using any compression utility (Ex: Windows Explorer, 7zip, WinRar).
Step 4
We need to add the location of Lua binaries to the system PATH so that Windows can call Lua from anywhere in the system.
Step 4.1. Navigate to Environment Variables. (Open Windows Explorer, right-click on This PC, and select properties.)
Step 4.2. Click on "Advanced System Settings" in the screen that appears and then click on "Environment Variables".
Step 4.3. In the system variables section, add the location of the Lua executables as a new entry for the Path variable.
Step 5
Check if the system identifies Lua by opening up a command prompt or a PowerShell window and typing the Lua command (Lua with the version – lua54).
Setting up a Lua development environment
Now that we have installed Lua in the system, we need a development environment to go ahead with coding. For that, we can choose between:
Let's create a file called "lua_basic.lua" in VSCode and save that file in the desired location. Then we will type some print statements there like the following.
Copy
print("Hello Lua")print(10*10)print("We have multiplied 10 by 10")
Step 2
Our Lua program needs to be compiled before running, so we need to create a Build Task. To do that, click on Terminal Menu, then Run Built Task and select the Configure Build Task Option.
( There will be different build task templates depending on the VSCode configuration. Select "Create tasks.json from template" and finally the "Others" option to define a custom build task.)
Run Build Task
Configure Build Task
Create tasks.json from template
Other
Step 2.1. We will add the following code block to configure the task. In that code block, we have defined a task called "Run Lua" that will run on the shell with the command "lua54". That command will take the current file as the argument and carry out a build operation.
Open up the "lua_basic.lua" file again. Then go to the "Terminal" again and click on "Run Build Task" or use the shortcut Ctrl+Shift+B.
This will compile the file and provide us with the output.
That's it! Now we have a working Lua development environment that can be used to create Lua scripts. We can use the official Lua reference manual to explore the Lua language further.
Lua is powerful
Lua is a powerful scripting language that has limitless potential to add functionality to any program on a multitude of platforms to suit any use case.
Empowering STEM educators to teach kids 21st century skills | Techstars Seattle 2021
Share via:
There's a chance you might have heard about the game Roblox. It's recently been making waves in the gaming community and has skyrocketed in popularity over the last few years, making it one of the most played games by kids and young adults.
In just the span of a year since the Coronavirus pandemic hit us, Roblox has grown an additional 50 Million users. Most of these users are between the ages of 7-16 years old.
Just what made Roblox so popular? How did it grow so big so quickly? Here are 6 reasons why Roblox is so popular.
1. It's Free to Play
You can download Roblox free of charge, and it is free to play. This is in contrast to Minecraft, an arguably similarly popular game that costs $26.99. Many kids don't have funds to spend on games yet, and Roblox lets you try the game out without costing anything.
While there are certain elements of the game that you can spend money on, for the most part, you can enjoy the game without ever spending a penny.
2. Available Across Multiple Platforms
Roblox captures a diverse audience by making itself available on practically everything. Roblox offers multiple ways to get online and play, even if you don't have a PC. It is available to play on tablets, smartphones, and even the XBOX.
The reason for this multi-platform availability is that the game itself is relatively lightweight. When it comes to resources and performance requirements, it doesn't need much. Any decent computer made within the last 7 years will be able to run it. Most mobile phones running either Android 5.0/iOS 8.0 or higher can also run the game. You can find a comprehensive list of requirements and supported devices here.
This means you can play with whoever you want to on virtually any platform you please. It's great for bonding with friends and sharing fun experiences.
3. Variety of Game Modes and Content
Let's delve deeper into the experience Roblox provides. Roblox is more of an app store than it is a standalone game. You have access to a plethora of different game modes, game types, and game genres.
There are Role-Playing (RP) games like Brookhaven RP, where you can build your own character from scratch. RPs let you create a character in a fictional world, and play them out. This is a great source of enjoyment for many.
Adopt Me! is arguably one of the most popular games and revolves around caregiving. Players can take on either the role of an adoptive parent or a child with needs to be met.
Yet another offering is the Tower of Hell. It is an obby (slang for Obstacle Course) with challenging courses that test your skills and patience.
Murder Mystery has recently gained popularity as well. It is a game similar to Among Us in that it is a social deduction game. Each round designates one random player as the murderer, one as the Sherrif, and up to 10 players as innocents. The goal for the murderer is to eliminate everyone before the Sherriff catches them. The goal for the Sherrif is to catch the murderer. And the goal for the innocents is to survive and aid the Sherrif in their investigation.
The diversity doesn't stop there. There are recreations of classic games like Pokemon, racing games, even a Windows Error Simulator. The charm of Roblox is that there's an endless stream of variety and that there's something for everyone. If you get bored of one game mode, you can hop into any of the others for an altogether different experience.
4. A Platform for Creativity
Roblox is also a platform that lets your build and create. You can bring to life almost any idea you have within Roblox. You are given the tools you need to create your own custom maps and games. There's also a thriving community of developers that you can ask for help if you're new.
Roblox is based on the Lua programming language and it is relatively easy to learn. It's so easy that even kids are learning it. The dev team for Roblox offers plenty of in-depth videos on their Youtube channel. The content in these videos ranges from complete beginner to advanced programmer.
All of this comes together to give people a creative outlet for their imagination. It's great to see all of the fun and exciting content available. There's never a dull moment in Roblox.
5. Big, Friendly Community
Social interaction is one of the most important aspects of gaming today. It's a way to make friends, share experiences, bond over similar interests, and go on digital adventures together. More people have met through gaming now than ever before. Online gaming can also help people feel less alone.
Roblox offers a massive community of people to interact with and play games with. With nearly 200 Million total users and over 42 Million daily active users as of March 2021, it's one of the biggest communities around. In light of the recent pandemic, this ability to easily make friends has been a driving force in Roblox's growing popularity. 50 million new users were added just in the last year.
With the most popular games in Roblox garnering over 250,000 regular players, there's no shortage of people to play with. Hop in a game like Royale High and you'll be delighted to see a healthy and thriving player base. We've had numerous stories of people connecting meaningfully through different games in Roblox and creating lasting friendships.
6. Developers Get Rewarded for Their Work
We mentioned previously that most of the popular games in Roblox were created by the community. Well, Roblox rewards developers whose creations are successful within the community.
Now would be a good time to introduce Robux, Roblox's premium currency. Robux can be acquired either through a monthly subscription to Roblox Premium or purchased separately. The monthly subscription can range from $4.99 a month to $19.99 a month, and additional options to buy more Roblux range up to $99.99 for 10,000 Robux.
While Robux isn't required to play as Roblox is free-to-play, some games offer avatar upgrades, items, perks, or other in-game content that you can buy with Robux. There are even games you have to purchase with Robux to be able to play.
Again, we stress that Robux isn't necessary to enjoy the game, but it can provide additional enjoyment to some.
So how do developers get rewarded? Roblox Corporation will share a cut of the Robux that your game earns if your game is popular enough to qualify. This is done through the Developer Exchange Program.
In 2020, Roblox paid out $250 million to developers through this program. With the most popular game developers getting over a million dollars. This number is set to grow in 2021 and has more and more people wanting to get out there and make some money off the next great idea for a game.
If this blog has got you interested in Roblox, then we've got more for you. In next week's blog, we'll be talking about how you can use Roblox as an effective method to teach kids coding in an engaging and fun way. Hope you enjoyed this week's blog.
Questions and Contact
If you'd like to know more about us and what we offer or have any questions about Roblox or other fun games our curricula use, feel free to contact us at info@gobrite.io or 425-665-7799 and we'll be happy to get back to you.
Any feedback or constructive criticism is greatly appreciated.