Skip to content

Updated garrysmod addon - #355

Merged
carsakiller merged 2 commits into
LuaLS:mainfrom
luttje:update-garrysmod-addon
Dec 2, 2026
Merged

carsakiller merged 2 commits into
LuaLS:mainfrom
luttje:update-garrysmod-addon

Conversation

@luttje

@luttje luttje commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Heya!

Another update for the garrysmod addon. Unlike previous updates, this one is not annotation-only: it adds a LuaLS plugin.

plugin.lua

Why garrysmod needs a plugin

A lot of garrysmod(GMod) code depends on conventions that static annotations can't express:

  • The file's path decides the class. Entities, weapons and effects are defined in files like lua/entities/my_entity.lua. While a file loads, the game gives it a global table (ENT, SWEP, EFFECT or TOOL) and then registers that table under the file or folder name (my_entity). So ENT means a different class in every file.
  • Classes are created by name. Code creates them with strings, such as ents.Create("my_entity") or vgui.Create("MyPanel"). Without a plugin, LuaLS can only return the generic base type.
  • Methods are generated at runtime. AccessorFunc(tbl, "m_Name", "Name") and NetworkVar("Int", "Health") create GetName/SetName-style methods from strings. LuaLS never saw those methods defined.
  • GMod preprocesses code. It rewrites DEFINE_BASECLASS("base") to local BaseClass = baseclass.Get("base") before running it, so plain Lua tooling sees invalid syntax.

config.json now sets Lua.runtime.plugin to ${addons}/garrysmod/module/plugin.lua.

The plugin only uses OnSetText and OnTransformAst, and only requires parser.guide and plugins.astHelper (no file or OS access). It adds:

  • Scripted classes: in files under entities/, weapons/, effects/ and stools/, ENT/SWEP/EFFECT/TOOL is typed as that file's own class.
  • Creating classes by name: ents.Create, ents.CreateClientside and Player:Give return the matching scripted class, and vgui.Create returns panel classes registered with vgui.Register.
  • Generated accessors: getters and setters from AccessorFunc and NetworkVar are typed, with the entity's own class as self.
  • DEFINE_BASECLASS: it is rewritten the same way GMod does it, so BaseClass is typed instead of flagged as a syntax error.

Annotation changes

  • vgui.Create has overloads that return the right type for each built-in panel class.
  • FindMetaTable has overloads that return the right type for each known metatable name (e.g. "Player" → Player).
  • CompileString overloads cover how its handleError argument works, and its return type is now optional.
  • Hooks can return values, including undocumented ones, so returns are no longer flagged.
  • Flag parameters that take an enum or a table also accept plain numbers.
  • Fixed a broken default Vector value.
  • Updated to the latest wiki content (new and changed functions, hooks, enums and structures).

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 😊

@carsakiller carsakiller added the Addon Update An update for an existing addon label Dec 2, 2026
@carsakiller

Copy link
Copy Markdown
Collaborator

Hello! That is quite the interesting environment with all kinds of special magic 😆

@carsakiller
carsakiller merged commit 183e900 into LuaLS:main Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Addon Update An update for an existing addon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants