Learn Lua in Neovim: Math & String Libraries — floor, random, sub, format & Dice Roller | Episode 23
2views
0015:19
T
Taught by Celeste AI - AI Coding Coach
View on YouTubeDescription
Lua ships with powerful built-in libraries. In this episode we explore the math library — floor, ceil, abs, max, min, pi, and
random — and the string library — sub, find, format, byte, and char. We finish by combining both to build a dice roller
function.
Every keystroke is shown on screen with 3-second pauses so you can follow along at your own pace.
What You'll Learn:
- math.floor / math.ceil — rounding down and up
- math.abs / math.max / math.min — absolute value and extremes
- math.pi — the constant pi, used for circle area
- math.randomseed / math.random — generating random numbers
- string.sub(s, i, j) — extracting substrings
- string.find(s, pattern) — searching within strings
- string.format — formatted output like printf
- string.byte / string.char — ASCII conversion
- Building a dice roller with roll_dice(count, sides)
Neovim Commands Used:
- Ctrl+d — scroll half a page down
- Ctrl+u — scroll half a page up
- bbb — move back three words
- cw — change word (fix a typo)
Timestamps:
0:00 Intro
0:12 Preview
0:44 Open file
1:07 Math Library — floor, ceil, abs, max, min
2:23 Run math basics
3:16 Circle Area with math.pi
4:36 Random Numbers with math.randomseed
5:39 Run pi, area, and random
6:21 String Library — sub and find
7:32 Run string basics
8:17 String Format — %s, %d, %.4f, %x
9:35 Byte and Char — ASCII conversion
10:15 Run format and byte/char
11:08 Dice Roller — roll_dice function
12:47 Run all seven sections
13:50 Review — Ctrl+d / Ctrl+u scrolling
14:00 Recap
14:32 Next: Modules and Require
Practice code: https://github.com/GoCelesteAI/learn-lua-in-neovim
This is Episode 23 of the Learn Lua in Neovim series. New episodes cover modules, metatables, OOP, and the Neovim Lua API — all
coded inside Neovim.
Taught by CelesteAI. Like & subscribe for more tutorials!
#lua #neovim #programming #tutorial #beginners #learnlua #luaprogramming #neovimtutorial #luamath #luastring #coding
Tags
lualua tutoriallearn lualua math librarylua string librarylua math.floorlua math.ceillua math.randomlua math.pilua string.sublua string.findlua string.formatlua string.bytelua string.charlua dice roller