# Lua — Fast Lightweight Embeddable Scripting Language > Lua is a powerful, efficient, and lightweight scripting language designed for embedding in applications, widely used in game development, configuration, and plugin systems. ## Install Save as a script file and run: # Lua — Fast Lightweight Embeddable Scripting Language ## Quick Use ```bash # Install on Ubuntu/Debian sudo apt install lua5.4 # Run a Lua script echo 'print("Hello from Lua")' > hello.lua lua hello.lua # Interactive REPL lua -i ``` ## Introduction Lua is a lightweight, high-level scripting language designed for embedding in host applications. Created at PUC-Rio in Brazil, Lua combines simple procedural syntax with powerful data description constructs based on associative arrays and extensible semantics. Its small footprint and fast interpreter make it the scripting language of choice for game engines, networking equipment, and extensible applications. ## What Lua Does - Provides an embeddable scripting engine with a clean C API for host application integration - Offers first-class functions, closures, coroutines, and metatables for flexible programming - Uses a single data structure (the table) for arrays, dictionaries, objects, and modules - Compiles to portable bytecode that runs on a register-based virtual machine - Supports incremental garbage collection with low pause times ## Architecture Overview Lua consists of a compiler that translates source code into bytecode and a register-based virtual machine that executes it. The C API provides a stack-based interface for exchanging data and calling functions between Lua and the host application. Metatables enable operator overloading and prototype-based object orientation. Coroutines provide cooperative multitasking through asymmetric coroutine semantics with explicit yield and resume. ## Self-Hosting & Configuration - Build from source with just a C compiler using make linux, make macosx, or make mingw - The complete interpreter and standard library compile to under 300 KB - Embed in C/C++ applications by linking liblua.a and including lua.h, lauxlib.h, and lualib.h - Use LuaRocks package manager to install community modules and libraries - Configure via require paths set in LUA_PATH and LUA_CPATH environment variables ## Key Features - Extremely small footprint: full interpreter under 300 KB compiled - One of the fastest scripting language interpreters available (even faster with LuaJIT) - Clean and well-documented C API for seamless host application embedding - Coroutines for cooperative multitasking without threads or callbacks - Metatables provide powerful metaprogramming capabilities for custom object systems ## Comparison with Similar Tools - **Python** — general-purpose language with a vast ecosystem; Lua is smaller and faster to embed but has fewer libraries - **JavaScript** — ubiquitous web language with V8/SpiderMonkey engines; Lua has a simpler embedding story and smaller runtime - **Luau** — Roblox's typed fork of Lua with performance optimizations and gradual typing - **Wren** — small embeddable scripting language with classes; Lua has broader industry adoption and ecosystem - **Squirrel** — C++-friendly scripting language used in games; Lua has wider community support and tooling ## FAQ **Q: Why is Lua popular in game development?** A: Lua's small size, fast execution, simple C API, and coroutine support make it easy to embed as a scripting layer in game engines for modding, AI, and UI logic. **Q: What is the difference between Lua and LuaJIT?** A: LuaJIT is a separate implementation by Mike Pall that uses a just-in-time compiler to achieve near-C performance. It is compatible with Lua 5.1 but does not support later Lua versions. **Q: Can Lua be used for standalone applications?** A: Yes. While designed for embedding, Lua works as a standalone scripting language with frameworks like LOVE2D for games and OpenResty for web servers. **Q: Is Lua dynamically or statically typed?** A: Lua is dynamically typed. Variables do not have types; values do. Lua supports nil, boolean, number, string, function, table, userdata, and thread types. ## Sources - https://github.com/lua/lua - https://www.lua.org/manual/5.4/ --- Source: https://tokrepo.com/en/workflows/asset-eb87d028 Author: Script Depot