Explain Lua code

Paste Lua, Roblox game scripts included, and Vibe explains what each table holds, what a colon call passes and how a metatable makes a class.

Leaderboard.lua

Up to 1,500 characters (about 60 lines). Your code is sent to Unvibe and Anthropic to write the explanation. Don't paste keys or passwords. Common key formats are refused.

Vibe25 lines selected

Press Explain it for the sample, or paste your own code first.

What this Lua sample shows

tables
The table is Lua's one data structure, and the sample uses it three ways: scores maps names to points, each { name = name, score = score } is a record, and rows and lines are lists numbered from 1. Reading a missing key gives nil, so self.scores[name] or 0 starts a new player at 0.
metatables
setmetatable({ scores = {} }, Leaderboard) makes a board that looks up any key it doesn't have in Leaderboard, because Leaderboard.__index is Leaderboard itself. The board holds only scores, so board:add finds add on Leaderboard. board:add("nova", 30) is short for board.add(board, "nova", 30), and that first argument is self.

Good to know

  • With nova adding 30 and then 20, blitz 45 and echo 50, board:top(3) returns 1. echo: 50, 2. nova: 50 and 3. blitz: 45.
  • pairs visits keys in no set order, so table.sort decides the order: higher scores first, and a tie goes by name, which is why echo comes before nova on 50 every time.
  • Names are compared as text, and in this run capital letters sorted before lowercase ones: three players tied on 10 come out as Bolt, Zed, alpha. Compare a.name:lower() < b.name:lower() to ignore case.
  • math.min(count, #rows) stops at the players there are: top(10) with three players returns three lines, and an empty board returns an empty table.
  • The sample uses only standard Lua, no Roblox APIs, and was run with Lua 5.5. In Roblox it would usually sit in a ModuleScript that ends with return Leaderboard, which other scripts load with require.

Watch out: Methods need the colon. board.add("nova", 5) with a dot passes "nova" as self and 5 as the name, and fails with attempt to index a nil value (field 'scores'). Leaving out the points fails too, with attempt to perform arithmetic on a nil value (local 'points').

Explain Lua code beside your editor

Unvibe is a free app for Mac and Windows. In the app there is no pasting: select code in any app and press Control+U (Ctrl+Alt+U on Windows).

Install on Mac

curl -fsSL https://unvibe.site/install.sh | bash

Paste into Terminal. Unvibe isn't notarized by Apple yet, so this is the smooth path.

Opening the .dmg the first time
  1. Open the .dmg and drag Unvibe to Applications.
  2. Open it once; macOS says it can't verify it. Click Done.
    macOS dialog: Unvibe Not Opened, with Done and Move to Trash
    Real screen, macOS 15
  3. System Settings › Privacy & Security › Open Anyway. Confirm, then enter your Mac password. The button shows for about an hour after you try to open Unvibe.
    macOS Privacy & Security, Security section: Unvibe was blocked to protect your Mac, with the Open Anyway button
    Real screen, macOS 15

The Terminal line checks the download against the published SHA-256 and Unvibe's self-signed signature before it installs anything. More help with the first open