1. Home
  2. /
  3. Lua
  4. /
  5. Ammo Tracker

Ammo Tracker - Lua Typing CST Test

Loading…

Ammo Tracker — Lua Code

Tracks ammo usage with shoot and reload actions.

ammo = 10

function updateUI()
	print('Ammo: ' .. ammo)
end

function shoot()
	ammo = ammo - 1
	updateUI()
end

function reload()
	ammo = 10
	updateUI()
end

-- Simulate actions
updateUI()
shoot()
shoot()
reload()

Lua Language Guide

Lua is a lightweight, high-level, multi-paradigm scripting language designed for embedded use in applications. It emphasizes simplicity, portability, and performance, and is widely used in games, embedded systems, and scripting engines.

Primary Use Cases

  • ▸Scripting in video games (e.g., Roblox, World of Warcraft, Angry Birds)
  • ▸Embedded scripting in applications
  • ▸Configuration and automation scripts
  • ▸Rapid prototyping and DSLs (domain-specific languages)
  • ▸Network services and lightweight servers

Notable Features

  • ▸Small and lightweight runtime
  • ▸Fast execution and JIT compilation (with LuaJIT)
  • ▸Dynamic typing and automatic memory management
  • ▸First-class functions and closures
  • ▸Extensible via C API

Origin & Creator

Created in 1993 by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, and Waldemar Celes at PUC-Rio, Brazil.

Industrial Note

Lua is specialized for embedding in applications such as video games, simulation software, and network applications, allowing host programs to expose custom APIs to Lua scripts.

More Lua Typing Exercises

Lua Button Press CounterLua Theme ToggleLua Score TrackerLua Simple TimerLua Health TrackerLua Level TrackerLua Coin CounterLua Star CollectorLua Power-Up Timer

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher