[{"data":1,"prerenderedAt":2550},["ShallowReactive",2],{"page-\u002Flua\u002F01-introduction-and-setup":3},{"id":4,"title":5,"body":6,"description":172,"extension":2544,"meta":2545,"navigation":34,"path":2546,"seo":2547,"stem":2548,"__hash__":2549},"content\u002Flua\u002F01-introduction-and-setup.md","01 — Introduction & Setup",{"type":7,"value":8,"toc":2513},"minimark",[9,13,81,157,260,349,518,662,766,918,1065,1229,1324,1478,1596,1721,1813,1957,2134,2275,2402,2509],[10,11,5],"h1",{"id":12},"_01-introduction-setup",[14,15,16,21,55],"question-wrapper",{},[17,18,20],"h3",{"id":19},"q1-what-is-lua-fundamentally-designed-to-be","Q1. What is Lua fundamentally designed to be?",[22,23,26,37,43,49],"ul",{"className":24},[25],"contains-task-list",[27,28,31,36],"li",{"className":29},[30],"task-list-item",[32,33],"input",{"disabled":34,"type":35},true,"checkbox"," A lightweight, embeddable scripting language meant to be hosted inside larger applications",[27,38,40,42],{"className":39},[30],[32,41],{"disabled":34,"type":35}," A general-purpose systems programming language for writing operating systems",[27,44,46,48],{"className":45},[30],[32,47],{"disabled":34,"type":35}," A markup language for describing web page layouts",[27,50,52,54],{"className":51},[30],[32,53],{"disabled":34,"type":35}," A statically-typed compiled language for high-performance servers",[56,57,58,62,70],"details",{},[59,60,61],"summary",{},"Show Answer",[63,64,65,69],"p",{},[66,67,68],"strong",{},"Answer:"," A — A lightweight, embeddable scripting language meant to be hosted inside larger applications",[63,71,72,75,76,80],{},[66,73,74],{},"Explanation:"," Lua was created in 1993 at PUC-Rio specifically to be embedded into C host applications as a configuration\u002Fextension language; its small footprint, C API, and minimal standard library all reflect that goal. It's not aimed at OS development (option B) or markup (option C); while it can run standalone scripts, that's a side effect of the reference ",[77,78,79],"code",{},"lua"," interpreter, not the language's primary design goal, and option D wrongly implies static typing and ahead-of-time compilation, which Lua doesn't have.",[14,82,83,94,132],{},[17,84,86,87,89,90,93],{"id":85},"q2-which-statement-accurately-describes-the-relationship-between-lua-the-referencepuc-lua-interpreter-and-luajit-luajit","Q2. Which statement accurately describes the relationship between ",[77,88,79],{}," (the reference\u002FPUC-Lua interpreter) and ",[77,91,92],{},"luajit"," (LuaJIT)?",[22,95,97,106,112,118],{"className":96},[25],[27,98,100,102,103,105],{"className":99},[30],[32,101],{"disabled":34,"type":35}," They are the same VM; ",[77,104,92],{}," is just a faster build flag for the reference interpreter",[27,107,109,111],{"className":108},[30],[32,110],{"disabled":34,"type":35}," LuaJIT is a strict superset that always supports every language feature added in the latest PUC-Lua release",[27,113,115,117],{"className":114},[30],[32,116],{"disabled":34,"type":35}," LuaJIT is a separate implementation with its own VM and JIT compiler, and its language support lags behind — it targets roughly Lua 5.1 semantics with some 5.2 extensions, not 5.4",[27,119,121,123,124,127,128,131],{"className":120},[30],[32,122],{"disabled":34,"type":35}," LuaJIT only works with Lua bytecode compiled by ",[77,125,126],{},"luac",", not with ",[77,129,130],{},".lua"," source files",[56,133,134,136,141],{},[59,135,61],{},[63,137,138,140],{},[66,139,68],{}," C — LuaJIT is a separate implementation with its own VM and JIT compiler, and its language support lags behind — it targets roughly Lua 5.1 semantics with some 5.2 extensions, not 5.4",[63,142,143,145,146,149,150,153,154,156],{},[66,144,74],{}," LuaJIT (by Mike Pall) is a from-scratch VM and JIT compiler with excellent performance, but its core language-version tracking stalled around 5.1 with a handful of 5.2-ish additions; it does not support Lua 5.3\u002F5.4 features such as the integer subtype, native bitwise-operator syntax, or ",[77,147,148],{},"\u003Cconst>","\u002F",[77,151,152],{},"\u003Cclose>"," attributes. Option A is wrong because they are distinct codebases, not a build flag; option B inverts reality; option D is wrong because LuaJIT compiles and runs ",[77,155,130],{}," source directly, just like PUC-Lua.",[14,158,160,164,193,234],{"language":159},"bash",[17,161,163],{"id":162},"q3-given-the-following-two-invocations-whats-the-key-difference-in-behavior","Q3. Given the following two invocations, what's the key difference in behavior?",[165,166,167],"code-wrapper",{"language":159},[168,169,173],"pre",{"className":170,"code":171,"language":159,"meta":172,"style":172},"language-bash shiki shiki-themes github-light github-dark","lua script.lua\nlua\n","",[77,174,175,187],{"__ignoreMap":172},[176,177,180,183],"span",{"class":178,"line":179},"line",1,[176,181,79],{"class":182},"sIsaT",[176,184,186],{"class":185},"sJ6F3"," script.lua\n",[176,188,190],{"class":178,"line":189},2,[176,191,192],{"class":182},"lua\n",[22,194,196,205,215,224],{"className":195},[25],[27,197,199,201,202],{"className":198},[30],[32,200],{"disabled":34,"type":35}," Both start an interactive REPL; the filename is ignored unless preceded by ",[77,203,204],{},"-i",[27,206,208,210,211,214],{"className":207},[30],[32,209],{"disabled":34,"type":35}," The first executes ",[77,212,213],{},"script.lua"," as a program and exits; the second (no arguments) starts the interactive read-eval-print loop",[27,216,218,220,221],{"className":217},[30],[32,219],{"disabled":34,"type":35}," The first is invalid syntax; you must use ",[77,222,223],{},"lua -f script.lua",[27,225,227,229,230,233],{"className":226},[30],[32,228],{"disabled":34,"type":35}," The second only works if a ",[77,231,232],{},".luarc"," config file is present in the current directory",[56,235,236,238,245],{},[59,237,61],{},[63,239,240,242,243,214],{},[66,241,68],{}," B — The first executes ",[77,244,213],{},[63,246,247,249,250,252,253,256,257,259],{},[66,248,74],{}," Passing a filename runs that chunk to completion and exits (unless the script itself starts a loop); running bare ",[77,251,79],{}," with no script argument drops you into the interactive prompt (",[77,254,255],{},">",") for evaluating statements and expressions one at a time. Option A confuses ",[77,258,204],{}," (which runs a script AND then keeps the REPL open) with plain script execution; options C and D describe flags and config files that don't exist in stock Lua.",[14,261,262,270,313],{},[17,263,265,266,269],{"id":264},"q4-what-best-distinguishes-luac-the-standalone-interpreter-from-lua-as-a-language-and-runtime","Q4. What best distinguishes ",[77,267,268],{},"lua.c"," (the standalone interpreter) from \"Lua\" as a language and runtime?",[22,271,273,285,293,301],{"className":272},[25],[27,274,276,278,279,281,282,284],{"className":275},[30],[32,277],{"disabled":34,"type":35}," ",[77,280,268],{}," is required to compile any ",[77,283,130],{}," file; without it Lua code cannot run at all",[27,286,288,278,290,292],{"className":287},[30],[32,289],{"disabled":34,"type":35},[77,291,268],{}," is the only supported way to call Lua from C++ or other languages",[27,294,296,278,298,300],{"className":295},[30],[32,297],{"disabled":34,"type":35},[77,299,268],{}," replaced the Lua VM starting in version 5.4",[27,302,304,278,306,308,309,312],{"className":303},[30],[32,305],{"disabled":34,"type":35},[77,307,268],{}," is a thin, optional command-line front-end built on the same ",[77,310,311],{},"liblua"," C API that any host application uses to embed Lua — the language itself doesn't require a standalone binary",[56,314,315,317,326],{},[59,316,61],{},[63,318,319,321,322,308,324,312],{},[66,320,68],{}," D — ",[77,323,268],{},[77,325,311],{},[63,327,328,330,331,333,334,336,337,339,340,342,343,345,346,348],{},[66,329,74],{}," Lua's core is a C library (",[77,332,311],{},") that exposes the Lua C API; ",[77,335,268],{}," is just a small sample client of that API that happens to ship as the ",[77,338,79],{}," command. Real-world embedding (games, editor configs, server scripting) links ",[77,341,311],{}," directly and often never touches ",[77,344,268],{},". Options A and B overstate the standalone binary's necessity, and option C is fabricated — the VM has evolved across versions, but ",[77,347,268],{}," never \"replaced\" it.",[14,350,351,359,439,482],{"language":79},[17,352,354,355,358],{"id":353},"q5-this-script-uses-a-gotolabel-pair-what-happens-when-you-run-it-with-lua-51-vs-lua-54","Q5. This script uses a ",[77,356,357],{},"goto","\u002Flabel pair. What happens when you run it with Lua 5.1 vs Lua 5.4?",[165,360,361],{"language":79},[168,362,365],{"className":363,"code":364,"language":79,"meta":172,"style":172},"language-lua shiki shiki-themes github-light github-dark","local i = 1\n::top::\nprint(i)\ni = i + 1\nif i \u003C= 3 then goto top end\n",[77,366,367,384,389,398,413],{"__ignoreMap":172},[176,368,369,373,377,380],{"class":178,"line":179},[176,370,372],{"class":371},"svdQ7","local",[176,374,376],{"class":375},"ssxIu"," i ",[176,378,379],{"class":371},"=",[176,381,383],{"class":382},"snvgF"," 1\n",[176,385,386],{"class":178,"line":189},[176,387,388],{"class":185},"::top::\n",[176,390,392,395],{"class":178,"line":391},3,[176,393,394],{"class":382},"print",[176,396,397],{"class":375},"(i)\n",[176,399,401,404,406,408,411],{"class":178,"line":400},4,[176,402,403],{"class":375},"i ",[176,405,379],{"class":371},[176,407,376],{"class":375},[176,409,410],{"class":371},"+",[176,412,383],{"class":382},[176,414,416,419,421,424,427,430,433,436],{"class":178,"line":415},5,[176,417,418],{"class":371},"if",[176,420,376],{"class":375},[176,422,423],{"class":371},"\u003C=",[176,425,426],{"class":382}," 3",[176,428,429],{"class":371}," then",[176,431,432],{"class":371}," goto",[176,434,435],{"class":185}," top",[176,437,438],{"class":371}," end\n",[22,440,442,451,460,473],{"className":441},[25],[27,443,445,447,448,450],{"className":444},[30],[32,446],{"disabled":34,"type":35}," It behaves identically on both — ",[77,449,357],{}," has existed since Lua 5.0",[27,452,454,456,457,459],{"className":453},[30],[32,455],{"disabled":34,"type":35}," It runs fine on 5.4 but fails to parse on 5.1, because ",[77,458,357],{},"\u002Flabels were introduced in Lua 5.2",[27,461,463,465,466,468,469,472],{"className":462},[30],[32,464],{"disabled":34,"type":35}," It runs fine on 5.1 but fails on 5.4, because ",[77,467,357],{}," was removed in favor of ",[77,470,471],{},"break"," in 5.3",[27,474,476,478,479,481],{"className":475},[30],[32,477],{"disabled":34,"type":35}," Neither version supports ",[77,480,357],{},"; only LuaJIT does",[56,483,484,486,493],{},[59,485,61],{},[63,487,488,490,491,459],{},[66,489,68],{}," B — It runs fine on 5.4 but fails to parse on 5.1, because ",[77,492,357],{},[63,494,495,278,497,499,500,503,504,506,507,510,511,514,515,517],{},[66,496,74],{},[77,498,357],{}," and ",[77,501,502],{},"::label::"," syntax were added in Lua 5.2; feeding this to a 5.1 interpreter (or most LuaJIT builds, which track roughly 5.1 syntax) raises a syntax error near ",[77,505,357],{}," or ",[77,508,509],{},"::",". ",[66,512,513],{},"Portability:"," code using ",[77,516,357],{}," is a quick way to accidentally require 5.2+, so it's worth checking the target interpreter's version before relying on it. Option C and D are invented behaviors; option A ignores the real version boundary.",[14,519,520,524,580,615],{"language":79},[17,521,523],{"id":522},"q6-what-does-this-print-under-lua-54","Q6. What does this print under Lua 5.4?",[165,525,526],{"language":79},[168,527,529],{"className":363,"code":528,"language":79,"meta":172,"style":172},"print(7 \u002F 2)\nprint(7 \u002F\u002F 2)\nprint(7.0 \u002F\u002F 2)\n",[77,530,531,550,565],{"__ignoreMap":172},[176,532,533,535,538,541,544,547],{"class":178,"line":179},[176,534,394],{"class":382},[176,536,537],{"class":375},"(",[176,539,540],{"class":382},"7",[176,542,543],{"class":371}," \u002F",[176,545,546],{"class":382}," 2",[176,548,549],{"class":375},")\n",[176,551,552,554,556,558,561,563],{"class":178,"line":189},[176,553,394],{"class":382},[176,555,537],{"class":375},[176,557,540],{"class":382},[176,559,560],{"class":371}," \u002F\u002F",[176,562,546],{"class":382},[176,564,549],{"class":375},[176,566,567,569,571,574,576,578],{"class":178,"line":391},[176,568,394],{"class":382},[176,570,537],{"class":375},[176,572,573],{"class":382},"7.0",[176,575,560],{"class":371},[176,577,546],{"class":382},[176,579,549],{"class":375},[22,581,583,591,599,607],{"className":582},[25],[27,584,586,278,588],{"className":585},[30],[32,587],{"disabled":34,"type":35},[77,589,590],{},"3.5  3  3.0",[27,592,594,278,596],{"className":593},[30],[32,595],{"disabled":34,"type":35},[77,597,598],{},"3  3  3",[27,600,602,278,604],{"className":601},[30],[32,603],{"disabled":34,"type":35},[77,605,606],{},"3.5  3.5  3.5",[27,608,610,278,612],{"className":609},[30],[32,611],{"disabled":34,"type":35},[77,613,614],{},"4  3  3.0",[56,616,617,619,626],{},[59,618,61],{},[63,620,621,623,624],{},[66,622,68],{}," A — ",[77,625,590],{},[63,627,628,278,630,632,633,636,637,510,640,643,644,647,648,651,652,647,655,658,659,661],{},[66,629,74],{},[77,631,149],{}," is always float division in Lua 5.3+, so ",[77,634,635],{},"7 \u002F 2"," yields ",[77,638,639],{},"3.5",[77,641,642],{},"\u002F\u002F"," is floor division, also introduced in 5.3, which preserves the \"more float-like\" operand's type: two integer operands yield an integer floor (",[77,645,646],{},"7 \u002F\u002F 2"," is ",[77,649,650],{},"3","), but if either operand is a float the result is a float floor (",[77,653,654],{},"7.0 \u002F\u002F 2",[77,656,657],{},"3.0","). Option B wrongly assumes ",[77,660,149],{}," truncates like C integer division; option D wrongly rounds instead of flooring, and also gets the type wrong for the first result.",[14,663,664,668,703,738],{"language":79},[17,665,667],{"id":666},"q7-what-happens-when-this-runs-on-lua-54","Q7. What happens when this runs on Lua 5.4?",[165,669,670],{"language":79},[168,671,673],{"className":363,"code":672,"language":79,"meta":172,"style":172},"local MAX_RETRIES \u003Cconst> = 5\nMAX_RETRIES = MAX_RETRIES + 1\n",[77,674,675,690],{"__ignoreMap":172},[176,676,677,679,682,684,687],{"class":178,"line":179},[176,678,372],{"class":371},[176,680,681],{"class":375}," MAX_RETRIES ",[176,683,148],{"class":371},[176,685,686],{"class":371}," =",[176,688,689],{"class":382}," 5\n",[176,691,692,695,697,699,701],{"class":178,"line":189},[176,693,694],{"class":375},"MAX_RETRIES ",[176,696,379],{"class":371},[176,698,681],{"class":375},[176,700,410],{"class":371},[176,702,383],{"class":382},[22,704,706,715,721,730],{"className":705},[25],[27,707,709,711,712,714],{"className":708},[30],[32,710],{"disabled":34,"type":35}," It runs fine; ",[77,713,148],{}," is just a linting hint with no runtime effect",[27,716,718,720],{"className":717},[30],[32,719],{"disabled":34,"type":35}," It raises a runtime error only if the reassignment line actually executes inside a loop",[27,722,724,726,727,729],{"className":723},[30],[32,725],{"disabled":34,"type":35}," It raises a compile-time error: attempt to assign to a ",[77,728,148],{}," variable",[27,731,733,278,735,737],{"className":732},[30],[32,734],{"disabled":34,"type":35},[77,736,148],{}," is only valid on function parameters, so this is a syntax error on the first line",[56,739,740,742,749],{},[59,741,61],{},[63,743,744,746,747,729],{},[66,745,68],{}," C — It raises a compile-time error: attempt to assign to a ",[77,748,148],{},[63,750,751,278,753,755,756,759,760,762,763,765],{},[66,752,74],{},[77,754,148],{}," attributes (Lua 5.4+) are enforced at compile time — the compiler rejects any later assignment to that name with an error like ",[77,757,758],{},"attempt to assign to const variable 'MAX_RETRIES'"," before the script even runs. Option A underestimates it (it's not merely advisory); option B wrongly treats it as a runtime-only, control-flow-dependent check; option D is false — ",[77,761,148],{}," attaches to ",[77,764,372],{}," declarations, not to parameters.",[14,767,768,775,852,888],{"language":79},[17,769,771,772,774],{"id":770},"q8-what-is-the-purpose-of-the-close-attribute-in-this-lua-54-snippet","Q8. What is the purpose of the ",[77,773,152],{}," attribute in this Lua 5.4 snippet?",[165,776,777],{"language":79},[168,778,780],{"className":363,"code":779,"language":79,"meta":172,"style":172},"local function open_log()\n  local f \u003Cclose> = io.open(\"app.log\", \"w\")\n  f:write(\"started\\n\")\nend\n",[77,781,782,795,823,847],{"__ignoreMap":172},[176,783,784,786,789,792],{"class":178,"line":179},[176,785,372],{"class":371},[176,787,788],{"class":371}," function",[176,790,791],{"class":182}," open_log",[176,793,794],{"class":375},"()\n",[176,796,797,800,803,805,807,810,812,815,818,821],{"class":178,"line":189},[176,798,799],{"class":371},"  local",[176,801,802],{"class":375}," f ",[176,804,152],{"class":371},[176,806,686],{"class":371},[176,808,809],{"class":382}," io.open",[176,811,537],{"class":375},[176,813,814],{"class":185},"\"app.log\"",[176,816,817],{"class":375},", ",[176,819,820],{"class":185},"\"w\"",[176,822,549],{"class":375},[176,824,825,828,831,834,836,839,842,845],{"class":178,"line":391},[176,826,827],{"class":182},"  f",[176,829,830],{"class":375},":",[176,832,833],{"class":382},"write",[176,835,537],{"class":375},[176,837,838],{"class":185},"\"started",[176,840,841],{"class":382},"\\n",[176,843,844],{"class":185},"\"",[176,846,549],{"class":375},[176,848,849],{"class":178,"line":400},[176,850,851],{"class":371},"end\n",[22,853,855,863,869,875],{"className":854},[25],[27,856,858,860,861],{"className":857},[30],[32,859],{"disabled":34,"type":35}," It makes the variable read-only for the rest of the block, identical to ",[77,862,148],{},[27,864,866,868],{"className":865},[30],[32,867],{"disabled":34,"type":35}," It closes over the enclosing function's upvalues to prevent memory leaks",[27,870,872,874],{"className":871},[30],[32,873],{"disabled":34,"type":35}," It is purely cosmetic documentation with no effect until Lua 5.5",[27,876,878,880,881,884,885],{"className":877},[30],[32,879],{"disabled":34,"type":35}," It marks the value as to-be-closed: when the variable goes out of scope (normally or via error), Lua automatically calls its ",[77,882,883],{},"__close"," metamethod, similar to RAII\u002F",[77,886,887],{},"defer",[56,889,890,892,901],{},[59,891,61],{},[63,893,894,896,897,884,899],{},[66,895,68],{}," D — It marks the value as to-be-closed: when the variable goes out of scope (normally or via error), Lua automatically calls its ",[77,898,883],{},[77,900,887],{},[63,902,903,278,905,907,908,910,911,914,915,917],{},[66,904,74],{},[77,906,152],{}," (5.4+) guarantees the value's ",[77,909,883],{}," metamethod runs when the variable leaves scope — including during error unwinding — giving deterministic cleanup (file handles, locks) without a manual ",[77,912,913],{},"pcall","-and-cleanup dance. Option A confuses it with the unrelated ",[77,916,148],{}," attribute; option B misapplies the term \"closure\" to something it doesn't mean here; option C is false — it is fully functional in 5.4, not a no-op reserved for a future version.",[14,919,920,924,962,1022],{"language":79},[17,921,923],{"id":922},"q9-you-run-this-snippet-with-lua-51-what-happens","Q9. You run this snippet with Lua 5.1. What happens?",[165,925,926],{"language":79},[168,927,929],{"className":363,"code":928,"language":79,"meta":172,"style":172},"local flags = 6\nlocal mask = 2\nprint(flags & mask)\n",[77,930,931,943,955],{"__ignoreMap":172},[176,932,933,935,938,940],{"class":178,"line":179},[176,934,372],{"class":371},[176,936,937],{"class":375}," flags ",[176,939,379],{"class":371},[176,941,942],{"class":382}," 6\n",[176,944,945,947,950,952],{"class":178,"line":189},[176,946,372],{"class":371},[176,948,949],{"class":375}," mask ",[176,951,379],{"class":371},[176,953,954],{"class":382}," 2\n",[176,956,957,959],{"class":178,"line":391},[176,958,394],{"class":382},[176,960,961],{"class":375},"(flags & mask)\n",[22,963,965,979,1000,1012],{"className":964},[25],[27,966,968,970,971,974,975,978],{"className":967},[30],[32,969],{"disabled":34,"type":35}," Prints ",[77,972,973],{},"2",", since ",[77,976,977],{},"&"," is bitwise AND and has worked the same way since Lua 5.0",[27,980,982,984,985,817,987,817,990,817,993,817,996,999],{"className":981},[30],[32,983],{"disabled":34,"type":35}," Raises a syntax error, because native bitwise operators (",[77,986,977],{},[77,988,989],{},"|",[77,991,992],{},"~",[77,994,995],{},"\u003C\u003C",[77,997,998],{},">>",") were only added in Lua 5.3",[27,1001,1003,970,1005,1008,1009,1011],{"className":1002},[30],[32,1004],{"disabled":34,"type":35},[77,1006,1007],{},"4",", because ",[77,1010,977],{}," is silently reinterpreted as string concatenation",[27,1013,1015,1017,1018,1021],{"className":1014},[30],[32,1016],{"disabled":34,"type":35}," Works, but only if you ",[77,1019,1020],{},"require(\"bit32\")"," first",[56,1023,1024,1026,1041],{},[59,1025,61],{},[63,1027,1028,1030,1031,817,1033,817,1035,817,1037,817,1039,999],{},[66,1029,68],{}," B — Raises a syntax error, because native bitwise operators (",[77,1032,977],{},[77,1034,989],{},[77,1036,992],{},[77,1038,995],{},[77,1040,998],{},[63,1042,1043,1045,1046,1048,1049,278,1052,1056,1057,1060,1061,1064],{},[66,1044,74],{}," Bitwise operator syntax is new to Lua 5.3; on 5.1 (and LuaJIT's default dialect) the parser doesn't recognize ",[77,1047,977],{}," as an operator at all, so it throws a syntax error. Lua 5.1 has no built-in bitwise support; Lua 5.2 added the ",[77,1050,1051],{},"bit32",[1053,1054,1055],"em",{},"library"," (function calls like ",[77,1058,1059],{},"bit32.band","), not the operator syntax, so option D conflates a different version's library with this version's operator — and the operator still wouldn't parse regardless of any ",[77,1062,1063],{},"require",". Options A and C describe fabricated behaviors.",[14,1066,1067,1075,1133,1183],{"language":79},[17,1068,1070,1071,1074],{"id":1069},"q10-given-the-table-below-what-does-printt0-t1-t3-output","Q10. Given the table below, what does ",[77,1072,1073],{},"print(t[0], t[1], t[3])"," output?",[165,1076,1077],{"language":79},[168,1078,1080],{"className":363,"code":1079,"language":79,"meta":172,"style":172},"local t = {10, 20, 30}\nprint(t[0], t[1], t[3])\n",[77,1081,1082,1110],{"__ignoreMap":172},[176,1083,1084,1086,1089,1091,1094,1097,1099,1102,1104,1107],{"class":178,"line":179},[176,1085,372],{"class":371},[176,1087,1088],{"class":375}," t ",[176,1090,379],{"class":371},[176,1092,1093],{"class":375}," {",[176,1095,1096],{"class":382},"10",[176,1098,817],{"class":375},[176,1100,1101],{"class":382},"20",[176,1103,817],{"class":375},[176,1105,1106],{"class":382},"30",[176,1108,1109],{"class":375},"}\n",[176,1111,1112,1114,1117,1120,1123,1126,1128,1130],{"class":178,"line":189},[176,1113,394],{"class":382},[176,1115,1116],{"class":375},"(t[",[176,1118,1119],{"class":382},"0",[176,1121,1122],{"class":375},"], t[",[176,1124,1125],{"class":382},"1",[176,1127,1122],{"class":375},[176,1129,650],{"class":382},[176,1131,1132],{"class":375},"])\n",[22,1134,1136,1153,1162,1170],{"className":1135},[25],[27,1137,1139,278,1141,1144,1145,1148,1149,1152],{"className":1138},[30],[32,1140],{"disabled":34,"type":35},[77,1142,1143],{},"nil  10  30"," — Lua arrays\u002Ftables are conventionally 1-indexed, so ",[77,1146,1147],{},"t[1]"," is the first element and ",[77,1150,1151],{},"t[0]"," is simply an unset key",[27,1154,1156,278,1158,1161],{"className":1155},[30],[32,1157],{"disabled":34,"type":35},[77,1159,1160],{},"10  20  30"," — indexing starts at 0 like most C-family languages",[27,1163,1165,1167,1168],{"className":1164},[30],[32,1166],{"disabled":34,"type":35}," An \"index out of range\" runtime error on ",[77,1169,1151],{},[27,1171,1173,278,1175,1178,1179,1182],{"className":1172},[30],[32,1174],{"disabled":34,"type":35},[77,1176,1177],{},"nil  nil  20"," — because ",[77,1180,1181],{},"{10, 20, 30}"," builds the table in reverse",[56,1184,1185,1187,1197],{},[59,1186,61],{},[63,1188,1189,623,1191,1144,1193,1148,1195,1152],{},[66,1190,68],{},[77,1192,1143],{},[77,1194,1147],{},[77,1196,1151],{},[63,1198,1199,1201,1202,1204,1205,1208,1209,1211,1212,1215,1216,1218,1219,817,1222,817,1225,1228],{},[66,1200,74],{}," The table constructor ",[77,1203,1181],{}," assigns sequential integer keys starting at 1 (",[77,1206,1207],{},"t[1]=10, t[2]=20, t[3]=30","); ",[77,1210,1151],{}," was never set, so indexing it just returns ",[77,1213,1214],{},"nil"," — Lua tables don't bounds-check or error on missing keys, they simply return ",[77,1217,1214],{},". This 1-based convention is a deliberate, pervasive design choice (matching ",[77,1220,1221],{},"string.sub",[77,1223,1224],{},"ipairs",[77,1226,1227],{},"table.insert",", and friends), not an off-by-one bug. Option B wrongly assumes C-style 0-indexing; option C invents an error Lua doesn't raise for plain table access; option D is not how table constructors work.",[14,1230,1231,1238,1267,1298],{"language":159},[17,1232,1234,1235,1237],{"id":1233},"q11-you-compile-a-script-with-lua-54s-luac-and-then-try-to-run-the-output-on-a-machine-that-only-has-lua-51-installed","Q11. You compile a script with Lua 5.4's ",[77,1236,126],{}," and then try to run the output on a machine that only has Lua 5.1 installed:",[165,1239,1240],{"language":159},[168,1241,1243],{"className":170,"code":1242,"language":159,"meta":172,"style":172},"luac5.4 -o app.luac app.lua\nlua5.1 app.luac\n",[77,1244,1245,1259],{"__ignoreMap":172},[176,1246,1247,1250,1253,1256],{"class":178,"line":179},[176,1248,1249],{"class":182},"luac5.4",[176,1251,1252],{"class":382}," -o",[176,1254,1255],{"class":185}," app.luac",[176,1257,1258],{"class":185}," app.lua\n",[176,1260,1261,1264],{"class":178,"line":189},[176,1262,1263],{"class":182},"lua5.1",[176,1265,1266],{"class":185}," app.luac\n",[22,1268,1270,1276,1286,1292],{"className":1269},[25],[27,1271,1273,1275],{"className":1272},[30],[32,1274],{"disabled":34,"type":35}," It runs correctly; Lua bytecode has been stable and cross-version compatible since 5.0",[27,1277,1279,1281,1282,1285],{"className":1278},[30],[32,1280],{"disabled":34,"type":35}," It automatically falls back to interpreting ",[77,1283,1284],{},"app.luac"," as source text",[27,1287,1289,1291],{"className":1288},[30],[32,1290],{"disabled":34,"type":35}," It fails — precompiled Lua bytecode is tied to the exact Lua version (and often platform\u002Fword-size) it was compiled for, so 5.4 bytecode is not portable to a 5.1 VM",[27,1293,1295,1297],{"className":1294},[30],[32,1296],{"disabled":34,"type":35}," It works, but only for scripts that don't use functions",[56,1299,1300,1302,1307],{},[59,1301,61],{},[63,1303,1304,1306],{},[66,1305,68],{}," C — It fails — precompiled Lua bytecode is tied to the exact Lua version (and often platform\u002Fword-size) it was compiled for, so 5.4 bytecode is not portable to a 5.1 VM",[63,1308,1309,278,1311,1313,1314,1316,1317,1319,1320,1323],{},[66,1310,74],{},[66,1312,513],{}," the Lua bytecode format changes between major versions (and can vary by platform, e.g. integer size), so ",[77,1315,126],{},"-compiled chunks are only guaranteed to load on a matching Lua version\u002Fbuild — running 5.4 bytecode on a 5.1 ",[77,1318,79],{}," typically fails with a \"bad header\" or version-mismatch load error. Option A is a common but false assumption carried over from source-level compatibility; options B and D describe behavior Lua doesn't have — a ",[77,1321,1322],{},".luac"," file is binary, not valid Lua source, so it can't be reinterpreted as text.",[14,1325,1326,1334,1376,1425],{"language":79},[17,1327,1329,1330,1333],{"id":1328},"q12-you-need-to-comment-out-this-block-which-itself-contains-a-sequence-inside-a-string-which-statement-about-the-comment-form-shown-is-correct","Q12. You need to comment out this block, which itself contains a ",[77,1331,1332],{},"]]"," sequence inside a string. Which statement about the comment form shown is correct?",[165,1335,1336],{"language":79},[168,1337,1339],{"className":363,"code":1338,"language":79,"meta":172,"style":172},"--[[\nlocal msg = \"use [[double brackets]] for long strings\"\nprint(msg)\n]]\n",[77,1340,1341,1347,1364,1371],{"__ignoreMap":172},[176,1342,1343],{"class":178,"line":179},[176,1344,1346],{"class":1345},"sdCPZ","--[[\n",[176,1348,1349,1352,1355,1358,1361],{"class":178,"line":189},[176,1350,1351],{"class":1345},"local msg = \"use [[double brackets]]",[176,1353,1354],{"class":371}," for",[176,1356,1357],{"class":375}," long ",[176,1359,1360],{"class":382},"strings",[176,1362,1363],{"class":185},"\"\n",[176,1365,1366,1368],{"class":178,"line":391},[176,1367,394],{"class":382},[176,1369,1370],{"class":375},"(msg)\n",[176,1372,1373],{"class":178,"line":400},[176,1374,1375],{"class":375},"]]\n",[22,1377,1379,1392,1402,1412],{"className":1378},[25],[27,1380,1382,1384,1385,1387,1388,1391],{"className":1381},[30],[32,1383],{"disabled":34,"type":35}," The form shown above works fine; Lua ignores nested ",[77,1386,1332],{}," inside a ",[77,1389,1390],{},"--[[ ... ]]"," comment",[27,1393,1395,1397,1398,1401],{"className":1394},[30],[32,1396],{"disabled":34,"type":35}," You must escape the inner brackets as ",[77,1399,1400],{},"\\]\\]"," for this to work",[27,1403,1405,1407,1408,1411],{"className":1404},[30],[32,1406],{"disabled":34,"type":35}," Block comments in Lua don't support multi-line content at all; only ",[77,1409,1410],{},"--"," is allowed",[27,1413,1415,1417,1418,1420,1421,1424],{"className":1414},[30],[32,1416],{"disabled":34,"type":35}," It's a syntax error \u002F the comment closes early — the first ",[77,1419,1332],{}," inside the string prematurely ends the comment, so use a longer bracket level like ",[77,1422,1423],{},"--[==[ ... ]==]"," instead",[56,1426,1427,1429,1438],{},[59,1428,61],{},[63,1430,1431,1433,1434,1420,1436,1424],{},[66,1432,68],{}," D — It's a syntax error \u002F the comment closes early — the first ",[77,1435,1332],{},[77,1437,1423],{},[63,1439,1440,278,1442,1444,1445,278,1448,1450,1451,1454,1455,817,1458,1461,1462,1464,1465,1467,1468,1470,1471,1473,1474,1477],{},[66,1441,74],{},[77,1443,1390],{}," closes at the ",[1053,1446,1447],{},"first",[77,1449,1332],{}," it encounters, regardless of context, so this comment actually ends right after ",[77,1452,1453],{},"[[double brackets"," and the remaining ",[77,1456,1457],{},"for long strings\"",[77,1459,1460],{},"print(msg)",", and the trailing ",[77,1463,1332],{}," are left as broken code. The fix is a higher long-bracket level — ",[77,1466,1423],{}," — whose closing delimiter must match the exact number of ",[77,1469,379],{}," signs, so an inner ",[77,1472,1332],{}," no longer terminates it. ",[66,1475,1476],{},"Debug:"," this is a classic Lua gotcha when commenting out code that itself contains long-bracket strings. Option A is the wrong-but-tempting assumption; option B invents an escape mechanism long brackets don't use; option C is false, since block comments explicitly exist for multi-line content.",[14,1479,1480,1484,1514,1562],{"language":79},[17,1481,1483],{"id":1482},"q13-what-happens-when-you-try-to-run-this","Q13. What happens when you try to run this?",[165,1485,1486],{"language":79},[168,1487,1489],{"className":363,"code":1488,"language":79,"meta":172,"style":172},"local end = 10\nprint(end)\n",[77,1490,1491,1503],{"__ignoreMap":172},[176,1492,1493,1495,1498,1500],{"class":178,"line":179},[176,1494,372],{"class":371},[176,1496,1497],{"class":371}," end",[176,1499,686],{"class":371},[176,1501,1502],{"class":382}," 10\n",[176,1504,1505,1507,1509,1512],{"class":178,"line":189},[176,1506,394],{"class":382},[176,1508,537],{"class":375},[176,1510,1511],{"class":371},"end",[176,1513,549],{"class":375},[22,1515,1517,1538,1547,1553],{"className":1516},[25],[27,1518,1520,1522,1523,1525,1526,1528,1529,149,1531,149,1534,1537],{"className":1519},[30],[32,1521],{"disabled":34,"type":35}," It runs fine and prints ",[77,1524,1096],{},"; ",[77,1527,1511],{}," is only special inside ",[77,1530,418],{},[77,1532,1533],{},"for",[77,1535,1536],{},"function"," blocks",[27,1539,1541,1543,1544,1546],{"className":1540},[30],[32,1542],{"disabled":34,"type":35}," It raises a syntax error, because ",[77,1545,1511],{}," is a reserved keyword and cannot be used as an identifier anywhere",[27,1548,1550,1552],{"className":1549},[30],[32,1551],{"disabled":34,"type":35}," It's allowed, but only in Lua 5.1 for backward compatibility with 4.x",[27,1554,1556,1558,1559,1561],{"className":1555},[30],[32,1557],{"disabled":34,"type":35}," It runs, but ",[77,1560,1511],{}," silently becomes a global instead of a local",[56,1563,1564,1566,1573],{},[59,1565,61],{},[63,1567,1568,1570,1571,1546],{},[66,1569,68],{}," B — It raises a syntax error, because ",[77,1572,1511],{},[63,1574,1575,1577,1578,1581,1582,1585,1586,506,1589,278,1592,1595],{},[66,1576,74],{}," Lua has a fixed, case-sensitive set of reserved keywords (",[77,1579,1580],{},"and, break, do, else, elseif, end, false, for, function, goto, if, in, local, nil, not, or, repeat, return, then, true, until, while",") that can never be used as identifiers, in any scope, in any version — the parser rejects ",[77,1583,1584],{},"local end = 10"," immediately. Note that ",[77,1587,1588],{},"End",[77,1590,1591],{},"END",[1053,1593,1594],{},"would"," be legal identifiers, since Lua is case-sensitive and only the exact lowercase keyword is reserved. Option A wrongly assumes context-sensitivity Lua doesn't have; options C and D invent exceptions that don't exist.",[14,1597,1598,1602,1633,1680],{"language":79},[17,1599,1601],{"id":1600},"q14-what-does-this-print","Q14. What does this print?",[165,1603,1604],{"language":79},[168,1605,1607],{"className":363,"code":1606,"language":79,"meta":172,"style":172},"print(nil, true, 10, \"hi\")\n",[77,1608,1609],{"__ignoreMap":172},[176,1610,1611,1613,1615,1617,1619,1622,1624,1626,1628,1631],{"class":178,"line":179},[176,1612,394],{"class":382},[176,1614,537],{"class":375},[176,1616,1214],{"class":382},[176,1618,817],{"class":375},[176,1620,1621],{"class":382},"true",[176,1623,817],{"class":375},[176,1625,1096],{"class":382},[176,1627,817],{"class":375},[176,1629,1630],{"class":185},"\"hi\"",[176,1632,549],{"class":375},[22,1634,1636,1649,1658,1671],{"className":1635},[25],[27,1637,1639,278,1641,1644,1645,1648],{"className":1638},[30],[32,1640],{"disabled":34,"type":35},[77,1642,1643],{},"nil true 10 hi"," with each argument converted via ",[77,1646,1647],{},"tostring()"," and separated by a tab character",[27,1650,1652,1654,1655,1657],{"className":1651},[30],[32,1653],{"disabled":34,"type":35}," An error, because ",[77,1656,394],{}," can't accept mixed types in one call",[27,1659,1661,1663,1664,1667,1668,1670],{"className":1660},[30],[32,1662],{"disabled":34,"type":35}," Only ",[77,1665,1666],{},"hi"," is printed; ",[77,1669,394],{}," in Lua only shows its last argument",[27,1672,1674,278,1676,1679],{"className":1673},[30],[32,1675],{"disabled":34,"type":35},[77,1677,1678],{},"nil, true, 10, \"hi\""," including the commas and quotes, since Lua prints the literal source",[56,1681,1682,1684,1692],{},[59,1683,61],{},[63,1685,1686,623,1688,1644,1690,1648],{},[66,1687,68],{},[77,1689,1643],{},[77,1691,1647],{},[63,1693,1694,278,1696,1698,1699,1701,1702,1704,1705,817,1708,1710,1711,1714,1715,1717,1718,1720],{},[66,1695,74],{},[77,1697,394],{}," calls ",[77,1700,1647],{}," on every argument it receives and writes them to stdout separated by tab characters, ending with a newline — so ",[77,1703,1214],{}," becomes the string ",[77,1706,1707],{},"\"nil\"",[77,1709,1621],{}," becomes ",[77,1712,1713],{},"\"true\"",", and no quotes are added around string arguments. Options B and C invent restrictions ",[77,1716,394],{}," doesn't have, since it's variadic and prints every argument it's given; option D confuses ",[77,1719,394],{},"'s runtime output with Lua source-code literal syntax.",[14,1722,1723,1735,1776],{},[17,1724,1726,1727,1730,1731,1734],{"id":1725},"q15-compared-to-ecosystems-like-nodejs-npm-or-python-pip-what-should-you-expect-out-of-the-box-from-a-fresh-lua-installation-regarding-package-management","Q15. Compared to ecosystems like Node.js (",[77,1728,1729],{},"npm",") or Python (",[77,1732,1733],{},"pip","), what should you expect out-of-the-box from a fresh Lua installation regarding package management?",[22,1736,1738,1748,1757,1770],{"className":1737},[25],[27,1739,1741,1743,1744,1747],{"className":1740},[30],[32,1742],{"disabled":34,"type":35}," Lua ships with a bundled package manager called ",[77,1745,1746],{},"luaget"," since 5.3",[27,1749,1751,278,1753,1756],{"className":1750},[30],[32,1752],{"disabled":34,"type":35},[77,1754,1755],{},"require()"," automatically downloads missing modules from a central registry the first time they're used",[27,1758,1760,1762,1763,1765,1766,1769],{"className":1759},[30],[32,1761],{"disabled":34,"type":35}," There is no bundled package manager — ",[77,1764,1755],{}," only loads modules already present on disk\u002F",[77,1767,1768],{},"package.path","; LuaRocks is the de-facto community package manager but must be installed separately",[27,1771,1773,1775],{"className":1772},[30],[32,1774],{"disabled":34,"type":35}," Package management is handled entirely by the operating system's package manager (apt\u002Fbrew), and Lua has no module system of its own",[56,1777,1778,1780,1789],{},[59,1779,61],{},[63,1781,1782,1784,1785,1765,1787,1769],{},[66,1783,68],{}," C — There is no bundled package manager — ",[77,1786,1755],{},[77,1788,1768],{},[63,1790,1791,1793,1794,1796,1797,149,1799,1802,1803,1806,1807,1809,1810,1812],{},[66,1792,74],{}," Historically Lua ships lean and dependency-free; ",[77,1795,1755],{}," is purely a local module loader that searches ",[77,1798,1768],{},[77,1800,1801],{},"package.cpath",", with zero networking involved. LuaRocks fills the npm\u002Fpip role but is a separate install, which trips up newcomers who expect ",[77,1804,1805],{},"npm install","-style tooling to exist by default. Option A invents a nonexistent tool; option B describes behavior ",[77,1808,1063],{}," has never had; option D understates that Lua does have its own ",[77,1811,1063],{},"\u002Fmodule mechanism independent of the OS.",[14,1814,1815,1819,1881,1920],{"language":79},[17,1816,1818],{"id":1817},"q16-which-statement-about-the-following-code-is-correct","Q16. Which statement about the following code is correct?",[165,1820,1821],{"language":79},[168,1822,1824],{"className":363,"code":1823,"language":79,"meta":172,"style":172},"local a = 1\nlocal b = 2;\nlocal c = 3;;\nprint(a + b + c)\n",[77,1825,1826,1837,1851,1865],{"__ignoreMap":172},[176,1827,1828,1830,1833,1835],{"class":178,"line":179},[176,1829,372],{"class":371},[176,1831,1832],{"class":375}," a ",[176,1834,379],{"class":371},[176,1836,383],{"class":382},[176,1838,1839,1841,1844,1846,1848],{"class":178,"line":189},[176,1840,372],{"class":371},[176,1842,1843],{"class":375}," b ",[176,1845,379],{"class":371},[176,1847,546],{"class":382},[176,1849,1850],{"class":375},";\n",[176,1852,1853,1855,1858,1860,1862],{"class":178,"line":391},[176,1854,372],{"class":371},[176,1856,1857],{"class":375}," c ",[176,1859,379],{"class":371},[176,1861,426],{"class":382},[176,1863,1864],{"class":375},";;\n",[176,1866,1867,1869,1872,1874,1876,1878],{"class":178,"line":400},[176,1868,394],{"class":382},[176,1870,1871],{"class":375},"(a ",[176,1873,410],{"class":371},[176,1875,1843],{"class":375},[176,1877,410],{"class":371},[176,1879,1880],{"class":375}," c)\n",[22,1882,1884,1894,1904,1910],{"className":1883},[25],[27,1885,1887,1889,1890,1893],{"className":1886},[30],[32,1888],{"disabled":34,"type":35}," Only the first two lines are valid; ",[77,1891,1892],{},"local c = 3;;"," is a syntax error from the double semicolon",[27,1895,1897,1899,1900,1903],{"className":1896},[30],[32,1898],{"disabled":34,"type":35}," The double semicolon on line 3 causes ",[77,1901,1902],{},"c"," to be declared twice, triggering a \"variable already defined\" error",[27,1905,1907,1909],{"className":1906},[30],[32,1908],{"disabled":34,"type":35}," Semicolons are required after every statement in Lua 5.4, unlike earlier versions, so lines 1 and 3 are actually errors",[27,1911,1913,1915,1916,1919],{"className":1912},[30],[32,1914],{"disabled":34,"type":35}," All lines are valid — semicolons are optional statement separators in Lua and can even appear as standalone empty statements, so ",[77,1917,1918],{},";;"," is harmless",[56,1921,1922,1924,1931],{},[59,1923,61],{},[63,1925,1926,1928,1929,1919],{},[66,1927,68],{}," D — All lines are valid — semicolons are optional statement separators in Lua and can even appear as standalone empty statements, so ",[77,1930,1918],{},[63,1932,1933,1935,1936,1939,1940,1942,1943,1945,1946,1949,1950,1953,1954,1956],{},[66,1934,74],{}," Lua treats ",[77,1937,1938],{},";"," as an optional statement separator; an empty statement (just ",[77,1941,1938],{},") is legal and does nothing, so ",[77,1944,1892],{}," is simply ",[77,1947,1948],{},"local c = 3"," followed by a no-op empty statement. ",[66,1951,1952],{},"Idiom:"," most style guides recommend omitting semicolons except where needed to disambiguate (e.g. before a line starting with ",[77,1955,537],{},"), but including them is never wrong. Options A and B invent errors that don't occur; option C is false in every Lua version, since semicolons have never been mandatory.",[14,1958,1959,1963,2047,2096],{"language":79},[17,1960,1962],{"id":1961},"q17-this-function-has-a-subtle-bug-what-is-it","Q17. This function has a subtle bug. What is it?",[165,1964,1965],{"language":79},[168,1966,1968],{"className":363,"code":1967,"language":79,"meta":172,"style":172},"function computeTotal(items)\n  total = 0\n  for i = 1, #items do\n    total = total + items[i]\n  end\n  return total\nend\n",[77,1969,1970,1980,1990,2013,2028,2033,2042],{"__ignoreMap":172},[176,1971,1972,1974,1977],{"class":178,"line":179},[176,1973,1536],{"class":371},[176,1975,1976],{"class":182}," computeTotal",[176,1978,1979],{"class":375},"(items)\n",[176,1981,1982,1985,1987],{"class":178,"line":189},[176,1983,1984],{"class":375},"  total ",[176,1986,379],{"class":371},[176,1988,1989],{"class":382}," 0\n",[176,1991,1992,1995,1997,1999,2002,2004,2007,2010],{"class":178,"line":391},[176,1993,1994],{"class":371},"  for",[176,1996,376],{"class":375},[176,1998,379],{"class":371},[176,2000,2001],{"class":382}," 1",[176,2003,817],{"class":375},[176,2005,2006],{"class":371},"#",[176,2008,2009],{"class":375},"items ",[176,2011,2012],{"class":371},"do\n",[176,2014,2015,2018,2020,2023,2025],{"class":178,"line":400},[176,2016,2017],{"class":375},"    total ",[176,2019,379],{"class":371},[176,2021,2022],{"class":375}," total ",[176,2024,410],{"class":371},[176,2026,2027],{"class":375}," items[i]\n",[176,2029,2030],{"class":178,"line":415},[176,2031,2032],{"class":371},"  end\n",[176,2034,2036,2039],{"class":178,"line":2035},6,[176,2037,2038],{"class":371},"  return",[176,2040,2041],{"class":375}," total\n",[176,2043,2045],{"class":178,"line":2044},7,[176,2046,851],{"class":371},[22,2048,2050,2060,2071,2083],{"className":2049},[25],[27,2051,2053,2055,2056,2059],{"className":2052},[30],[32,2054],{"disabled":34,"type":35}," There is no bug; ",[77,2057,2058],{},"total"," is correctly scoped to the function since it's assigned inside it",[27,2061,2063,278,2065,2067,2068,2070],{"className":2062},[30],[32,2064],{"disabled":34,"type":35},[77,2066,2058],{}," is missing a ",[77,2069,372],{}," declaration, so it's created as a global variable — it can silently collide with other code using the same name",[27,2072,2074,278,2076,2079,2080],{"className":2073},[30],[32,2075],{"disabled":34,"type":35},[77,2077,2078],{},"#items"," is invalid syntax; length must be computed with ",[77,2081,2082],{},"items.length",[27,2084,2086,2088,2089,2091,2092,2095],{"className":2085},[30],[32,2087],{"disabled":34,"type":35}," The ",[77,2090,1533],{}," loop should use ",[77,2093,2094],{},"ipairs(items)"," instead, or it won't iterate at all",[56,2097,2098,2100,2109],{},[59,2099,61],{},[63,2101,2102,2104,2105,2067,2107,2070],{},[66,2103,68],{}," B — ",[77,2106,2058],{},[77,2108,372],{},[63,2110,2111,2113,2114,2117,2118,2120,2121,2123,2124,2127,2128,2130,2131,2133],{},[66,2112,74],{}," Lua's default assignment behavior is global-by-default — ",[77,2115,2116],{},"total = 0"," inside the function, without ",[77,2119,372],{},", creates (or overwrites) a global variable, not a function-local one. It \"happens to work\" here because it's reset to 0 on every call, but it pollutes the global namespace and could clash with an unrelated global named ",[77,2122,2058],{}," elsewhere in a large embedded application; the fix is ",[77,2125,2126],{},"local total = 0",". Option A misses the footgun precisely because the code superficially works; option C is false, since ",[77,2129,2006],{}," is Lua's built-in length operator; option D is a style preference, not a bug, since the numeric ",[77,2132,1533],{}," loop shown works fine for a dense array-like table.",[14,2135,2136,2140,2182,2231],{"language":79},[17,2137,2139],{"id":2138},"q18-what-does-this-print-on-a-standard-lua-54-build","Q18. What does this print on a standard Lua 5.4 build?",[165,2141,2142],{"language":79},[168,2143,2145],{"className":363,"code":2144,"language":79,"meta":172,"style":172},"print(math.type(1), math.type(1.0), 1 == 1.0)\n",[77,2146,2147],{"__ignoreMap":172},[176,2148,2149,2151,2153,2156,2158,2160,2163,2165,2167,2170,2172,2174,2177,2180],{"class":178,"line":179},[176,2150,394],{"class":382},[176,2152,537],{"class":375},[176,2154,2155],{"class":382},"math.type",[176,2157,537],{"class":375},[176,2159,1125],{"class":382},[176,2161,2162],{"class":375},"), ",[176,2164,2155],{"class":382},[176,2166,537],{"class":375},[176,2168,2169],{"class":382},"1.0",[176,2171,2162],{"class":375},[176,2173,1125],{"class":382},[176,2175,2176],{"class":371}," ==",[176,2178,2179],{"class":382}," 1.0",[176,2181,549],{"class":375},[22,2183,2185,2198,2213,2222],{"className":2184},[25],[27,2186,2188,278,2190,2193,2194,2197],{"className":2187},[30],[32,2189],{"disabled":34,"type":35},[77,2191,2192],{},"integer  float  true"," — 5.4 distinguishes integer and float subtypes internally, but ",[77,2195,2196],{},"=="," still compares them by mathematical value",[27,2199,2201,278,2203,2206,2207,2209,2210],{"className":2200},[30],[32,2202],{"disabled":34,"type":35},[77,2204,2205],{},"number  number  true"," — Lua only has one numeric type, so ",[77,2208,2155],{}," always returns ",[77,2211,2212],{},"\"number\"",[27,2214,2216,278,2218,2221],{"className":2215},[30],[32,2217],{"disabled":34,"type":35},[77,2219,2220],{},"integer  float  false"," — different subtypes are never considered equal",[27,2223,2225,2227,2228,2230],{"className":2224},[30],[32,2226],{"disabled":34,"type":35}," This errors, because ",[77,2229,2155],{}," doesn't exist until Lua 5.5",[56,2232,2233,2235,2243],{},[59,2234,61],{},[63,2236,2237,623,2239,2193,2241,2197],{},[66,2238,68],{},[77,2240,2192],{},[77,2242,2196],{},[63,2244,2245,2247,2248,2251,2252,647,2255,2257,2258,2261,2262,2265,2266,2268,2269,2271,2272,2274],{},[66,2246,74],{}," Since Lua 5.3, numbers have two subtypes — integer and float — distinguishable via ",[77,2249,2250],{},"math.type()",", but arithmetic and comparison operators still treat them as one unified \"number\" for equality purposes, so ",[77,2253,2254],{},"1 == 1.0",[77,2256,1621],{}," even though their subtypes differ (",[77,2259,2260],{},"\"integer\""," vs ",[77,2263,2264],{},"\"float\"","). ",[66,2267,513],{}," this subtype distinction doesn't exist in Lua 5.1\u002F5.2 or in LuaJIT's default number model, where all numbers are doubles and ",[77,2270,2155],{}," isn't available, so code relying on it silently breaks on those runtimes. Option B describes pre-5.3 behavior; option C wrongly assumes subtype mismatch breaks numeric equality; option D is fabricated, since ",[77,2273,2155],{}," has existed since 5.3.",[14,2276,2277,2284,2319,2361],{"language":79},[17,2278,2280,2281,2283],{"id":2279},"q19-in-a-modern-53-interactive-lua-session-whats-the-difference-between-typing-these-two-entries-at-the-prompt","Q19. In a modern (5.3+) interactive ",[77,2282,79],{}," session, what's the difference between typing these two entries at the prompt?",[165,2285,2286],{"language":79},[168,2287,2289],{"className":363,"code":2288,"language":79,"meta":172,"style":172},"> 2 + 2\n> print(2 + 2)\n",[77,2290,2291,2302],{"__ignoreMap":172},[176,2292,2293,2295,2297,2300],{"class":178,"line":179},[176,2294,255],{"class":371},[176,2296,546],{"class":382},[176,2298,2299],{"class":371}," +",[176,2301,954],{"class":382},[176,2303,2304,2306,2309,2311,2313,2315,2317],{"class":178,"line":189},[176,2305,255],{"class":371},[176,2307,2308],{"class":382}," print",[176,2310,537],{"class":375},[176,2312,973],{"class":382},[176,2314,2299],{"class":371},[176,2316,546],{"class":382},[176,2318,549],{"class":375},[22,2320,2322,2330,2336,2353],{"className":2321},[25],[27,2323,2325,2327,2328],{"className":2324},[30],[32,2326],{"disabled":34,"type":35}," They behave differently: the first is a syntax error because bare expressions aren't valid statements, so you must always call ",[77,2329,394],{},[27,2331,2333,2335],{"className":2332},[30],[32,2334],{"disabled":34,"type":35}," The first only works in LuaJIT's REPL, not in standard Lua",[27,2337,2339,2341,2342,2345,2346,2349,2350,2352],{"className":2338},[30],[32,2340],{"disabled":34,"type":35}," They behave the same way: the standalone expression ",[77,2343,2344],{},"2 + 2"," is auto-detected by the REPL, implicitly wrapped as ",[77,2347,2348],{},"return 2 + 2",", and its result is printed, same visible output as the explicit ",[77,2351,394],{}," call",[27,2354,2356,2358,2359],{"className":2355},[30],[32,2357],{"disabled":34,"type":35}," The first silently discards the result and prints nothing, while only the second shows ",[77,2360,1007],{},[56,2362,2363,2365,2376],{},[59,2364,61],{},[63,2366,2367,2369,2370,2345,2372,2349,2374,2352],{},[66,2368,68],{}," C — They behave the same way: the standalone expression ",[77,2371,2344],{},[77,2373,2348],{},[77,2375,394],{},[63,2377,2378,2380,2381,2383,2384,2387,2388,2390,2391,2394,2395,2398,2399,2401],{},[66,2379,74],{}," Since Lua 5.2's ",[77,2382,268],{},", when a line typed at the interactive prompt doesn't parse as a valid statement, the REPL retries it prefixed with ",[77,2385,2386],{},"return",", then prints any returned values — so typing a bare expression is a convenient shortcut that ends up displaying the same ",[77,2389,1007],{}," as an explicit ",[77,2392,2393],{},"print(2 + 2)",". Older 5.1-style REPLs instead required an explicit ",[77,2396,2397],{},"=2+2"," shortcut for this. Option A wrongly treats the shortcut as invalid; option B is false, since this is standard ",[77,2400,268],{}," behavior, not LuaJIT-specific; option D invents silent-discard behavior that doesn't happen.",[14,2403,2404,2408,2451,2484],{"language":79},[17,2405,2407],{"id":2406},"q20-youre-embedding-a-scripting-layer-into-a-performance-sensitive-c-application-and-the-scripts-must-use-this-pattern-unmodified","Q20. You're embedding a scripting layer into a performance-sensitive C application, and the scripts must use this pattern unmodified:",[165,2409,2410],{"language":79},[168,2411,2413],{"className":363,"code":2412,"language":79,"meta":172,"style":172},"local flags \u003Cconst> = 0xF0 & 0x3C\nlocal step = 10 \u002F\u002F 3\n",[77,2414,2415,2434],{"__ignoreMap":172},[176,2416,2417,2419,2421,2423,2425,2428,2431],{"class":178,"line":179},[176,2418,372],{"class":371},[176,2420,937],{"class":375},[176,2422,148],{"class":371},[176,2424,686],{"class":371},[176,2426,2427],{"class":382}," 0xF0",[176,2429,2430],{"class":375}," & ",[176,2432,2433],{"class":382},"0x3C\n",[176,2435,2436,2438,2441,2443,2446,2448],{"class":178,"line":189},[176,2437,372],{"class":371},[176,2439,2440],{"class":375}," step ",[176,2442,379],{"class":371},[176,2444,2445],{"class":382}," 10",[176,2447,560],{"class":371},[176,2449,2450],{"class":382}," 3\n",[22,2452,2454,2460,2466,2472],{"className":2453},[25],[27,2455,2457,2459],{"className":2456},[30],[32,2458],{"disabled":34,"type":35}," LuaJIT, because it's always faster and a strict superset of PUC-Lua",[27,2461,2463,2465],{"className":2462},[30],[32,2464],{"disabled":34,"type":35}," Lua 5.1, since bitwise and floor-division support was available from the very first release",[27,2467,2469,2471],{"className":2468},[30],[32,2470],{"disabled":34,"type":35}," Any Lua version works identically, since these are all part of core Lua syntax since 5.0",[27,2473,2475,2477,2478,2480,2481,2483],{"className":2474},[30],[32,2476],{"disabled":34,"type":35}," Lua 5.3 or newer (e.g. 5.4), because ",[77,2479,148],{},", native bitwise operators, and ",[77,2482,642],{}," all require 5.3+ language support that LuaJIT's default dialect doesn't provide",[56,2485,2486,2488,2497],{},[59,2487,61],{},[63,2489,2490,2492,2493,2480,2495,2483],{},[66,2491,68],{}," D — Lua 5.3 or newer (e.g. 5.4), because ",[77,2494,148],{},[77,2496,642],{},[63,2498,2499,278,2501,2503,2504,499,2506,2508],{},[66,2500,74],{},[77,2502,148],{}," is 5.4-only, while ",[77,2505,977],{},[77,2507,642],{}," require 5.3+; LuaJIT's mainline branch tracks roughly 5.1 syntax plus a few extras and does not parse this snippet, so despite LuaJIT's raw speed advantage, it's the wrong choice when the requirement is running this specific 5.3+\u002F5.4 syntax unmodified — a real-world case where \"faster\" and \"compatible\" pull in different directions. Option A is the tempting-but-wrong performance-first answer; options B and C are simply factually wrong about when these features were introduced.",[2510,2511,2512],"style",{},"html pre.shiki code .sIsaT, html code.shiki .sIsaT{--shiki-default:#6F42C1;--shiki-github-dark:#B392F0}html pre.shiki code .sJ6F3, html code.shiki .sJ6F3{--shiki-default:#032F62;--shiki-github-dark:#9ECBFF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .github-dark .shiki span {color: var(--shiki-github-dark);background: var(--shiki-github-dark-bg);font-style: var(--shiki-github-dark-font-style);font-weight: var(--shiki-github-dark-font-weight);text-decoration: var(--shiki-github-dark-text-decoration);}html.github-dark .shiki span {color: var(--shiki-github-dark);background: var(--shiki-github-dark-bg);font-style: var(--shiki-github-dark-font-style);font-weight: var(--shiki-github-dark-font-weight);text-decoration: var(--shiki-github-dark-text-decoration);}html pre.shiki code .svdQ7, html code.shiki .svdQ7{--shiki-default:#D73A49;--shiki-github-dark:#F97583}html pre.shiki code .ssxIu, html code.shiki .ssxIu{--shiki-default:#24292E;--shiki-github-dark:#E1E4E8}html pre.shiki code .snvgF, html code.shiki .snvgF{--shiki-default:#005CC5;--shiki-github-dark:#79B8FF}html pre.shiki code .sdCPZ, html code.shiki .sdCPZ{--shiki-default:#6A737D;--shiki-github-dark:#6A737D}",{"title":172,"searchDepth":189,"depth":189,"links":2514},[2515,2516,2518,2519,2521,2523,2524,2525,2527,2528,2530,2532,2534,2535,2536,2538,2539,2540,2541,2543],{"id":19,"depth":391,"text":20},{"id":85,"depth":391,"text":2517},"Q2. Which statement accurately describes the relationship between lua (the reference\u002FPUC-Lua interpreter) and luajit (LuaJIT)?",{"id":162,"depth":391,"text":163},{"id":264,"depth":391,"text":2520},"Q4. What best distinguishes lua.c (the standalone interpreter) from \"Lua\" as a language and runtime?",{"id":353,"depth":391,"text":2522},"Q5. This script uses a goto\u002Flabel pair. What happens when you run it with Lua 5.1 vs Lua 5.4?",{"id":522,"depth":391,"text":523},{"id":666,"depth":391,"text":667},{"id":770,"depth":391,"text":2526},"Q8. What is the purpose of the \u003Cclose> attribute in this Lua 5.4 snippet?",{"id":922,"depth":391,"text":923},{"id":1069,"depth":391,"text":2529},"Q10. Given the table below, what does print(t[0], t[1], t[3]) output?",{"id":1233,"depth":391,"text":2531},"Q11. You compile a script with Lua 5.4's luac and then try to run the output on a machine that only has Lua 5.1 installed:",{"id":1328,"depth":391,"text":2533},"Q12. You need to comment out this block, which itself contains a ]] sequence inside a string. Which statement about the comment form shown is correct?",{"id":1482,"depth":391,"text":1483},{"id":1600,"depth":391,"text":1601},{"id":1725,"depth":391,"text":2537},"Q15. Compared to ecosystems like Node.js (npm) or Python (pip), what should you expect out-of-the-box from a fresh Lua installation regarding package management?",{"id":1817,"depth":391,"text":1818},{"id":1961,"depth":391,"text":1962},{"id":2138,"depth":391,"text":2139},{"id":2279,"depth":391,"text":2542},"Q19. In a modern (5.3+) interactive lua session, what's the difference between typing these two entries at the prompt?",{"id":2406,"depth":391,"text":2407},"md",{},"\u002Flua\u002F01-introduction-and-setup",{"title":5,"description":172},"lua\u002F01-introduction-and-setup","cIZUhiDaAJPW1Ul4nDsBd5qfWpBamtb2hplglFE-fEA",1787335397337]