Repository navigation
Updated garrysmod addon - #355
Merged
Merged
Conversation
carsakiller
approved these changes
Dec 2, 2026
Collaborator
|
Hello! That is quite the interesting environment with all kinds of special magic 😆 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Heya!
Another update for the garrysmod addon. Unlike previous updates, this one is not annotation-only: it adds a LuaLS plugin.
plugin.luaWhy garrysmod needs a plugin
A lot of garrysmod(GMod) code depends on conventions that static annotations can't express:
lua/entities/my_entity.lua. While a file loads, the game gives it a global table (ENT,SWEP,EFFECTorTOOL) and then registers that table under the file or folder name (my_entity). SoENTmeans a different class in every file.ents.Create("my_entity")orvgui.Create("MyPanel"). Without a plugin, LuaLS can only return the generic base type.AccessorFunc(tbl, "m_Name", "Name")andNetworkVar("Int", "Health")createGetName/SetName-style methods from strings. LuaLS never saw those methods defined.DEFINE_BASECLASS("base")tolocal BaseClass = baseclass.Get("base")before running it, so plain Lua tooling sees invalid syntax.config.jsonnow setsLua.runtime.pluginto${addons}/garrysmod/module/plugin.lua.The plugin only uses
OnSetTextandOnTransformAst, and only requiresparser.guideandplugins.astHelper(no file or OS access). It adds:entities/,weapons/,effects/andstools/,ENT/SWEP/EFFECT/TOOLis typed as that file's own class.ents.Create,ents.CreateClientsideandPlayer:Givereturn the matching scripted class, andvgui.Createreturns panel classes registered withvgui.Register.AccessorFuncandNetworkVarare typed, with the entity's own class asself.DEFINE_BASECLASS: it is rewritten the same way GMod does it, soBaseClassis typed instead of flagged as a syntax error.Annotation changes
vgui.Createhas overloads that return the right type for each built-in panel class.FindMetaTablehas overloads that return the right type for each known metatable name (e.g."Player"→Player).CompileStringoverloads cover how itshandleErrorargument works, and its return type is now optional.Vectorvalue.This is my first time working with LuaLS plugins, so let me know if we got anything wrong or if you'd like something done differently!
Thanks in advance for reviewing and merging once again, much appreciated 😊