[{"data":1,"prerenderedAt":1238},["ShallowReactive",2],{"page-\u002Flua":3},{"id":4,"title":5,"body":6,"description":1230,"extension":1231,"meta":1232,"navigation":1233,"path":1234,"seo":1235,"stem":1236,"__hash__":1237},"content\u002Flua\u002Findex.md","Learn Lua — Zero to Hero",{"type":7,"value":8,"toc":1207},"minimark",[9,14,18,26,31,60,64,100,104,109,230,234,291,295,385,389,459,463,535,539,608,612,616,619,653,657,659,723,727,730,770,774,777,804,808,1043,1047],[10,11,13],"h1",{"id":12},"learn-lua-zero-to-hero","📖 Learn Lua — Zero to Hero",[15,16,17],"p",{},"A code-first, production-grade Lua curriculum. Every chapter is structured around annotated code blocks: complex implementations, anti-patterns with fixes, performance tips, edge cases, and debugging challenges. Minimal prose, maximum signal.",[15,19,20,21,25],{},"Lua is a lightweight, embeddable scripting language with a register-based VM, used in game engines (Roblox, Garry's Mod, Defold), configuration (Neovim, AwesomeWM), databases (Redis), networking (OpenResty, Nginx), and embedded systems. Its entire runtime is a C library — the ",[22,23,24],"code",{},"lua"," executable is a 200-line wrapper.",[27,28,30],"h2",{"id":29},"how-to-use-this-course","How to Use This Course",[32,33,34,42,48,54],"ol",{},[35,36,37,41],"li",{},[38,39,40],"strong",{},"Read sequentially"," (01 → 16) for a structured path from runtime architecture to capstone projects.",[35,43,44,47],{},[38,45,46],{},"Jump to a chapter"," as a reference when you hit a concept in production.",[35,49,50,53],{},[38,51,52],{},"Run every code example"," — they're written as self-contained, executable scripts.",[35,55,56,59],{},[38,57,58],{},"Solve the Spot the Bug challenges"," before reading the answers.",[27,61,63],{"id":62},"prerequisites","Prerequisites",[65,66,67,78,88,97],"ul",{},[35,68,69,70,73,74,77],{},"Lua 5.4+ installed (",[22,71,72],{},"brew install lua"," \u002F ",[22,75,76],{},"apt install lua5.4","), or LuaJIT 2.1+.",[35,79,80,83,84,87],{},[22,81,82],{},"luarocks"," for package management (",[22,85,86],{},"brew install luarocks",").",[35,89,90,93,94,87],{},[22,91,92],{},"luacheck"," for linting (",[22,95,96],{},"luarocks install luacheck",[35,98,99],{},"Comfort with at least one other dynamic language (Python, JS, Ruby).",[27,101,103],{"id":102},"curriculum","Curriculum",[105,106,108],"h3",{"id":107},"part-i-foundations-execution-model","Part I — Foundations & Execution Model",[110,111,112,128],"table",{},[113,114,115],"thead",{},[116,117,118,122,125],"tr",{},[119,120,121],"th",{},"#",[119,123,124],{},"Topic",[119,126,127],{},"Why It Matters",[129,130,131,162,180,201],"tbody",{},[116,132,133,137,144],{},[134,135,136],"td",{},"01",[134,138,139],{},[140,141,143],"a",{"href":142},"\u002Flua\u002F01-getting-started","Runtime Architecture & Execution",[134,145,146,147,150,151,150,154,157,158,161],{},"Chunk compilation, ",[22,148,149],{},"load","\u002F",[22,152,153],{},"loadfile",[22,155,156],{},"require"," pipeline, ",[22,159,160],{},"_G"," registry, sandboxing, hot-reload.",[116,163,164,167,173],{},[134,165,166],{},"02",[134,168,169],{},[140,170,172],{"href":171},"\u002Flua\u002F02-variables-and-data-types","Types, Scoping & Memory",[134,174,175,176,179],{},"8-type system, integer\u002Ffloat duality, ",[22,177,178],{},"_ENV"," mechanics, upvalue cells, table reference semantics, weak tables.",[116,181,182,185,191],{},[134,183,184],{},"03",[134,186,187],{},[140,188,190],{"href":189},"\u002Flua\u002F03-functions","Functions, Closures & TCO",[134,192,193,194,150,197,200],{},"First-class functions, MRV truncation rules, varargs with ",[22,195,196],{},"select",[22,198,199],{},"pack",", proper tail calls, state machines.",[116,202,203,206,212],{},[134,204,205],{},"04",[134,207,208],{},[140,209,211],{"href":210},"\u002Flua\u002F04-control-flow","Control Flow & Iterators",[134,213,214,217,218,221,222,225,226,229],{},[22,215,216],{},"if"," as statement, numeric\u002Fgeneric ",[22,219,220],{},"for"," with the iterator protocol, table dispatch as ",[22,223,224],{},"switch",", ",[22,227,228],{},"goto"," for state machines.",[105,231,233],{"id":232},"part-ii-tables-data-structures","Part II — Tables & Data Structures",[110,235,236,246],{},[113,237,238],{},[116,239,240,242,244],{},[119,241,121],{},[119,243,124],{},[119,245,127],{},[129,247,248,266],{},[116,249,250,253,259],{},[134,251,252],{},"05",[134,254,255],{},[140,256,258],{"href":257},"\u002Flua\u002F05-tables-and-objects","Tables, OOP & Data Structures",[134,260,261,262,265],{},"Array\u002Fhash internals, reference vs value, shallow\u002Fdeep copy with cycles, OOP via ",[22,263,264],{},"__index",", mixins, linked list, ring buffer, object pool.",[116,267,268,271,277],{},[134,269,270],{},"06",[134,272,273],{},[140,274,276],{"href":275},"\u002Flua\u002F06-string-manipulation","Strings, Patterns & Binary",[134,278,279,280,283,284,150,287,290],{},"Immutable interned strings, Lua pattern engine (not regex), captures, frontier ",[22,281,282],{},"%f",", UTF-8, ",[22,285,286],{},"string.byte",[22,288,289],{},"char"," for binary protocols.",[105,292,294],{"id":293},"part-iii-metaprogramming-concurrency","Part III — Metaprogramming & Concurrency",[110,296,297,307],{},[113,298,299],{},[116,300,301,303,305],{},[119,302,121],{},[119,304,124],{},[119,306,127],{},[129,308,309,336,362],{},[116,310,311,314,320],{},[134,312,313],{},"07",[134,315,316],{},[140,317,319],{"href":318},"\u002Flua\u002F07-metatables-and-metamethods","Metatables & Metamethods",[134,321,322,323,150,325,328,329,150,332,335],{},"Full metamethod reference, operator overloading, ",[22,324,264],{},[22,326,327],{},"__newindex"," proxies, read-only tables, ",[22,330,331],{},"__gc",[22,333,334],{},"__close"," for resources.",[116,337,338,341,347],{},[134,339,340],{},"08",[134,342,343],{},[140,344,346],{"href":345},"\u002Flua\u002F08-modules-and-packages","Modules & Packages",[134,348,349,351,352,150,355,358,359,361],{},[22,350,156],{}," cache, ",[22,353,354],{},"package.searchers",[22,356,357],{},"preload",", circular dependency resolution, hot-reload, dependency injection, ",[22,360,82],{},".",[116,363,364,367,373],{},[134,365,366],{},"11",[134,368,369],{},[140,370,372],{"href":371},"\u002Flua\u002F11-coroutines","Coroutines & Generators",[134,374,375,150,378,150,381,384],{},[22,376,377],{},"create",[22,379,380],{},"resume",[22,382,383],{},"yield"," protocol, stackful yielding, generators as iterators, producer-consumer pipelines, cooperative scheduler.",[105,386,388],{"id":387},"part-iv-robustness-io","Part IV — Robustness & I\u002FO",[110,390,391,401],{},[113,392,393],{},[116,394,395,397,399],{},[119,396,121],{},[119,398,124],{},[119,400,127],{},[129,402,403,431],{},[116,404,405,408,414],{},[134,406,407],{},"09",[134,409,410],{},[140,411,413],{"href":412},"\u002Flua\u002F09-error-handling","Error Handling",[134,415,416,419,420,150,423,426,427,430],{},[22,417,418],{},"error"," levels, ",[22,421,422],{},"pcall",[22,424,425],{},"xpcall",", structured errors with metatables, retry with backoff, circuit breaker, ",[22,428,429],{},"\u003Cclose>"," cleanup.",[116,432,433,436,442],{},[134,434,435],{},"10",[134,437,438],{},[140,439,441],{"href":440},"\u002Flua\u002F10-io-and-files","I\u002FO, Files & Binary",[134,443,444,445,225,448,150,451,454,455,458],{},"File handle lifecycle, streaming with ",[22,446,447],{},":lines()",[22,449,450],{},"seek",[22,452,453],{},"tell",", binary I\u002FO, ",[22,456,457],{},"io.popen"," subprocess, atomic writes, CSV\u002FINI parsers.",[105,460,462],{"id":461},"part-v-standard-library-performance","Part V — Standard Library & Performance",[110,464,465,475],{},[113,466,467],{},[116,468,469,471,473],{},[119,470,121],{},[119,472,124],{},[119,474,127],{},[129,476,477,509],{},[116,478,479,482,488],{},[134,480,481],{},"12",[134,483,484],{},[140,485,487],{"href":486},"\u002Flua\u002F12-standard-library","Standard Library Deep-Dive",[134,489,490,493,494,497,498,500,501,504,505,508],{},[22,491,492],{},"math"," (random\u002Fprecision\u002Finteger), ",[22,495,496],{},"os"," (time\u002Fdate\u002Fenv), ",[22,499,110],{}," (sort\u002Fmove\u002Fpack), ",[22,502,503],{},"debug"," (introspection\u002Fhooks), ",[22,506,507],{},"package"," (searchers\u002Fpreload).",[116,510,511,514,520],{},[134,512,513],{},"13",[134,515,516],{},[140,517,519],{"href":518},"\u002Flua\u002F13-performance","Performance & LuaJIT",[134,521,522,523,526,527,530,531,534],{},"Global vs local cost, table rehash avoidance, ",[22,524,525],{},"table.concat"," vs ",[22,528,529],{},"..",", closure allocation, ",[22,532,533],{},"collectgarbage"," profiling, LuaJIT FFI.",[105,536,538],{"id":537},"part-vi-engineering-capstone","Part VI — Engineering & Capstone",[110,540,541,551],{},[113,542,543],{},[116,544,545,547,549],{},[119,546,121],{},[119,548,124],{},[119,550,127],{},[129,552,553,577,594],{},[116,554,555,558,564],{},[134,556,557],{},"14",[134,559,560],{},[140,561,563],{"href":562},"\u002Flua\u002F14-testing","Testing & Mocking",[134,565,566,567,570,571,225,574,361],{},"Assertion library, parametric\u002Ftable-based tests, ",[22,568,569],{},"package.preload"," mocking, dependency injection, coverage with ",[22,572,573],{},"debug.sethook",[22,575,576],{},"busted",[116,578,579,582,588],{},[134,580,581],{},"15",[134,583,584],{},[140,585,587],{"href":586},"\u002Flua\u002F15-best-practices","Best Practices & Patterns",[134,589,590,591,593],{},"Strict mode, module design, error architecture, RAII via ",[22,592,429],{},", config layering, logging, anti-patterns catalog.",[116,595,596,599,605],{},[134,597,598],{},"16",[134,600,601],{},[140,602,604],{"href":603},"\u002Flua\u002F16-exercises-and-projects","Capstone Projects",[134,606,607],{},"JSON parser, coroutine pipeline, ORM query builder, plugin sandbox system, LRU cache, binary search, type checker, mini-REPL.",[27,609,611],{"id":610},"learning-path-suggestions","Learning Path Suggestions",[105,613,615],{"id":614},"if-youre-coming-from-pythonruby","If you're coming from Python\u002FRuby",[15,617,618],{},"Focus on:",[65,620,621,629,634,648],{},[35,622,623,625,626,628],{},[38,624,166],{}," — ",[22,627,178],{}," and integer\u002Ffloat duality are unique to Lua",[35,630,631,633],{},[38,632,252],{}," — tables are not dicts; array\u002Fhash duality",[35,635,636,638,639,642,643,150,645,647],{},[38,637,313],{}," — metatables are not ",[22,640,641],{},"__getattr__","; ",[22,644,264],{},[22,646,327],{}," as proxies",[35,649,650,652],{},[38,651,366],{}," — coroutines are stackful (can yield from nested calls)",[105,654,656],{"id":655},"if-youre-coming-from-javascript","If you're coming from JavaScript",[15,658,618],{},[65,660,661,676,688,705,714],{},[35,662,663,625,665,668,669,672,673],{},[38,664,136],{},[22,666,667],{},"load()"," with custom env is like ",[22,670,671],{},"new Function()"," + ",[22,674,675],{},"with",[35,677,678,680,681,150,684,687],{},[38,679,166],{}," — 1-indexed arrays, only ",[22,682,683],{},"nil",[22,685,686],{},"false"," are falsy (0 and \"\" are truthy)",[35,689,690,692,693,696,697,700,701,704],{},[38,691,270],{}," — Lua patterns are NOT regex (no ",[22,694,695],{},"|",", no lookahead, ",[22,698,699],{},"%"," instead of ",[22,702,703],{},"\\",")",[35,706,707,709,710,713],{},[38,708,313],{}," — metatables are like ",[22,711,712],{},"Proxy"," but older and more limited",[35,715,716,718,719,722],{},[38,717,366],{}," — coroutines are like generators but stackful (no ",[22,720,721],{},"yield*"," needed)",[105,724,726],{"id":725},"if-youre-embedding-lua-in-c-a-game-engine","If you're embedding Lua in C \u002F a game engine",[15,728,729],{},"Read all chapters, then focus on:",[65,731,732,739,748,753,758,765],{},[35,733,734,625,736,738],{},[38,735,136],{},[22,737,667],{}," with sandbox env is your security boundary",[35,740,741,743,744,747],{},[38,742,166],{}," — types map to C types (table → ",[22,745,746],{},"lua_Table",", userdata → C object)",[35,749,750,752],{},[38,751,252],{}," — tables are the data interchange format with C",[35,754,755,757],{},[38,756,313],{}," — metatables for custom C types and operator overloading",[35,759,760,625,762,764],{},[38,761,340],{},[22,763,569],{}," for embedded modules (no filesystem)",[35,766,767,769],{},[38,768,581],{}," — strict mode for catching bugs in untrusted scripts",[105,771,773],{"id":772},"if-youre-a-senior-engineer","If you're a senior engineer",[15,775,776],{},"Skim 01–04. Read deeply:",[65,778,779,784,789,794,799],{},[35,780,781,783],{},[38,782,252],{}," (Tables — the data model)",[35,785,786,788],{},[38,787,313],{}," (Metatables — the extension mechanism)",[35,790,791,793],{},[38,792,366],{}," (Coroutines — the concurrency primitive)",[35,795,796,798],{},[38,797,513],{}," (Performance — where LuaJIT changes the game)",[35,800,801,803],{},[38,802,598],{}," (Capstone — integration of all concepts)",[27,805,807],{"id":806},"key-differences-from-other-languages","Key Differences from Other Languages",[110,809,810,826],{},[113,811,812],{},[116,813,814,817,820,823],{},[119,815,816],{},"Concept",[119,818,819],{},"Lua",[119,821,822],{},"JavaScript",[119,824,825],{},"Python",[129,827,828,841,878,892,909,925,947,968,990,1004,1017],{},[116,829,830,833,836,839],{},[134,831,832],{},"Array indexing",[134,834,835],{},"1-based",[134,837,838],{},"0-based",[134,840,838],{},[116,842,843,846,853,866],{},[134,844,845],{},"Falsy values",[134,847,848,225,850,852],{},[22,849,683],{},[22,851,686],{}," only",[134,854,855,225,858,225,861,225,864],{},[22,856,857],{},"0",[22,859,860],{},"\"\"",[22,862,863],{},"null",[22,865,686],{},[134,867,868,225,870,225,872,225,875],{},[22,869,857],{},[22,871,860],{},[22,873,874],{},"None",[22,876,877],{},"False",[116,879,880,883,886,889],{},[134,881,882],{},"Composite type",[134,884,885],{},"Table (only)",[134,887,888],{},"Object\u002FArray\u002FMap",[134,890,891],{},"dict\u002Flist\u002Ftuple\u002Fset",[116,893,894,897,900,903],{},[134,895,896],{},"Regex",[134,898,899],{},"Lua patterns (simpler)",[134,901,902],{},"Full regex",[134,904,905,908],{},[22,906,907],{},"re"," module",[116,910,911,914,919,922],{},[134,912,913],{},"Inheritance",[134,915,916,918],{},[22,917,264],{}," chain",[134,920,921],{},"Prototype chain",[134,923,924],{},"Class-based",[116,926,927,930,933,942],{},[134,928,929],{},"Concurrency",[134,931,932],{},"Coroutines (cooperative)",[134,934,935,150,938,941],{},[22,936,937],{},"async",[22,939,940],{},"await"," (event loop)",[134,943,944,941],{},[22,945,946],{},"asyncio",[116,948,949,952,958,963],{},[134,950,951],{},"Ternary",[134,953,954,957],{},[22,955,956],{},"a and b or c"," (trap!)",[134,959,960],{},[22,961,962],{},"a ? b : c",[134,964,965],{},[22,966,967],{},"b if a else c",[116,969,970,973,979,987],{},[134,971,972],{},"Block scope",[134,974,975,978],{},[22,976,977],{},"local"," in blocks",[134,980,981,150,984,978],{},[22,982,983],{},"let",[22,985,986],{},"const",[134,988,989],{},"Yes (functions\u002Fclasses)",[116,991,992,995,998,1001],{},[134,993,994],{},"Tail calls",[134,996,997],{},"Guaranteed (PTC)",[134,999,1000],{},"No (most engines)",[134,1002,1003],{},"No (recursion limit)",[116,1005,1006,1009,1012,1015],{},[134,1007,1008],{},"String interning",[134,1010,1011],{},"Yes (all strings)",[134,1013,1014],{},"Some (interned literals)",[134,1016,1014],{},[116,1018,1019,1022,1029,1036],{},[134,1020,1021],{},"Module system",[134,1023,1024,672,1026],{},[22,1025,156],{},[22,1027,1028],{},"package.loaded",[134,1030,1031,150,1034],{},[22,1032,1033],{},"import",[22,1035,156],{},[134,1037,1038,150,1040],{},[22,1039,1033],{},[22,1041,1042],{},"__import__",[27,1044,1046],{"id":1045},"tooling","Tooling",[110,1048,1049,1062],{},[113,1050,1051],{},[116,1052,1053,1056,1059],{},[119,1054,1055],{},"Tool",[119,1057,1058],{},"Purpose",[119,1060,1061],{},"Install",[129,1063,1064,1077,1092,1105,1118,1132,1147,1162,1177,1192],{},[116,1065,1066,1070,1073],{},[134,1067,1068],{},[22,1069,24],{},[134,1071,1072],{},"Reference interpreter (PUC-Rio)",[134,1074,1075],{},[22,1076,72],{},[116,1078,1079,1084,1087],{},[134,1080,1081],{},[22,1082,1083],{},"luajit",[134,1085,1086],{},"JIT compiler (10-100x faster)",[134,1088,1089],{},[22,1090,1091],{},"brew install luajit",[116,1093,1094,1098,1101],{},[134,1095,1096],{},[22,1097,82],{},[134,1099,1100],{},"Package manager",[134,1102,1103],{},[22,1104,86],{},[116,1106,1107,1111,1114],{},[134,1108,1109],{},[22,1110,92],{},[134,1112,1113],{},"Static analyzer (globals, shadowing)",[134,1115,1116],{},[22,1117,96],{},[116,1119,1120,1124,1127],{},[134,1121,1122],{},[22,1123,576],{},[134,1125,1126],{},"BDD test framework",[134,1128,1129],{},[22,1130,1131],{},"luarocks install busted",[116,1133,1134,1139,1142],{},[134,1135,1136],{},[22,1137,1138],{},"luaunit",[134,1140,1141],{},"Lightweight test framework",[134,1143,1144],{},[22,1145,1146],{},"luarocks install luaunit",[116,1148,1149,1154,1157],{},[134,1150,1151],{},[22,1152,1153],{},"lfs",[134,1155,1156],{},"LuaFileSystem (directory access)",[134,1158,1159],{},[22,1160,1161],{},"luarocks install luafilesystem",[116,1163,1164,1169,1172],{},[134,1165,1166],{},[22,1167,1168],{},"lpeg",[134,1170,1171],{},"Parsing Expression Grammars",[134,1173,1174],{},[22,1175,1176],{},"luarocks install lpeg",[116,1178,1179,1184,1187],{},[134,1180,1181],{},[22,1182,1183],{},"cjson",[134,1185,1186],{},"Fast JSON (C-backed)",[134,1188,1189],{},[22,1190,1191],{},"luarocks install lua-cjson",[116,1193,1194,1199,1202],{},[134,1195,1196],{},[22,1197,1198],{},"luasocket",[134,1200,1201],{},"Networking (TCP\u002FUDP\u002FHTTP)",[134,1203,1204],{},[22,1205,1206],{},"luarocks install luasocket",{"title":1208,"searchDepth":1209,"depth":1209,"links":1210},"",2,[1211,1212,1213,1222,1228,1229],{"id":29,"depth":1209,"text":30},{"id":62,"depth":1209,"text":63},{"id":102,"depth":1209,"text":103,"children":1214},[1215,1217,1218,1219,1220,1221],{"id":107,"depth":1216,"text":108},3,{"id":232,"depth":1216,"text":233},{"id":293,"depth":1216,"text":294},{"id":387,"depth":1216,"text":388},{"id":461,"depth":1216,"text":462},{"id":537,"depth":1216,"text":538},{"id":610,"depth":1209,"text":611,"children":1223},[1224,1225,1226,1227],{"id":614,"depth":1216,"text":615},{"id":655,"depth":1216,"text":656},{"id":725,"depth":1216,"text":726},{"id":772,"depth":1216,"text":773},{"id":806,"depth":1209,"text":807},{"id":1045,"depth":1209,"text":1046},"A comprehensive, code-first Lua curriculum for mid-to-senior engineers. Covers the runtime architecture, types, functions, tables, metatables, coroutines, I\u002FO, performance, testing, and capstone projects. Production-grade examples with edge cases, anti-patterns, and real-world system patterns.","md",{},true,"\u002Flua",{"title":5,"description":1230},"lua\u002Findex","DtAc0p3TcMqO5-fARU0AxPWjn46O38OMht_A52fN5zA",1789924650759]