fix: std functions should match official manuals#973
fix: std functions should match official manuals#973EfveZombie wants to merge 1 commit intoEmmyLuaLs:mainfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the accuracy of EmmyLua type annotations for the Lua standard library. By meticulously comparing existing stubs against official Lua manuals from versions 5.1 to 5.4, it ensures that function signatures, parameter types, return values, and version-specific behaviors are correctly represented. This effort improves static analysis capabilities and provides more reliable type hints for developers working with Lua. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request provides a comprehensive and valuable update to the EmmyLua standard library stubs, aligning them more closely with the official Lua manuals for versions 5.1 through 5.4. The changes are well-researched and systematically applied across multiple modules, correcting parameter types, return types, and version guards. I've found a couple of minor areas for further improvement in debug.lua to enhance consistency with the official documentation, but overall this is an excellent set of fixes.
| ---@param value any | ||
| ---@param n integer | ||
| ---@return userdata | ||
| ---@return userdata? |
There was a problem hiding this comment.
| ---@param thread? thread | ||
| ---@param message? string|T | ||
| ---@param level? integer | ||
| ---@return string |
There was a problem hiding this comment.
| --- When the first argument is not a thread and not nil, it is treated as an optional message. | ||
| --- In that case, the traceback is generated for the current thread and the second argument, | ||
| --- if provided, specifies the starting level. | ||
| ---@version 5.1 |
| function warn(message) end | ||
| ---@param msg1 string | ||
| ---@param ... string | ||
| function warn(msg1, ...) end |
Summary of Changes
This PR systematically audits and corrects the EmmyLua type-annotation stubs under
crates/emmylua_code_analysis/resources/std/so that parameter types, return types, version guards, and doc-comments accurately reflect the official Lua manuals (5.1 through 5.4).File-by-File Breakdown
1.
coroutine.lua(+12 / −2)coroutine.isyieldable(co)coparameter name to the function signaturecoargumentcoroutine.running()(5.1)thread?onlycoroutine.running()returnsnilwhen called from the main thread (no boolean)coroutine.running()(≥5.2)thread, string→thread, boolean2.
debug.lua(+42 / −18)debug.gethook()thread→function?, string, integer; overload updated similarlydebuglib.InfoWhataliaslalinedefined→lastlinedefineddebug.getupvalue()string?andany?(nilable)nilwhen the index is out of rangedebug.setlocal()string?nilon invalid leveldebug.setupvalue()string?nilwhen index is out of rangedebug.setuservalue()userdata?nilper the manualdebug.traceback()Tpassthrough for non-string messagesmessageis neither a string nor nil, it is returned as-is (identity passthrough). The previous annotation did not model this3.
global.lua(+3 / −2)dofile()table→any ...dofilereturns all values returned by the chunk, not necessarily a tablerawset()@return tablerawsetreturns the table being modifiedwarn()message→msg1, ...; accepts variadic stringswarnaccepts multiple string fragments concatenated together4.
math.lua(+20 / −2)math.abs()xand-x"math.randomseed()(5.1–5.3)@version 5.1, 5.2, 5.3guardmath.randomseed()(≥5.4)x, yand returnsinteger, integerrandomseedto accept two optional seed components and return themmath.type()'integer'|'float'|'nil'→'integer'|'float'|nil'nil'(string literal) is incorrect; the function returns actualnil5.
os.lua(+2 / −4)os.exit()(≥5.2)codeparameter type changed toboolean|integer, made optional; removed erroneous@return integeros.exitdoes not return;codecan be a boolean (true/false) in Lua ≥5.2os.exit()(5.1)codemade optional; removed@return integeros.exitnever returns6.
string.lua(+8 / −5)string.gmatch()(≥5.4)initparameterinitposition argumentstring.pack()string→string|number|integerstring.packpacks numbers and integers, not just strings7.
table.lua(+1 / −3)table.insert()@return integerfrom both the overload and the main signaturetable.insertreturns nothingtable.sort()@return integertable.sortreturns nothing (sorts in-place)8.
utf8.lua(+24 / −2)utf8.codes()string→fun(s: string, i?: integer): integer, integer(iterator)utf8.codesreturns an iterator function, not a stringutf8.codes()(≥5.4)laxparameterlaxboolean flagutf8.codepoint()(≥5.4)laxparameterutf8.len()laxparameterlaxflag