Skip to content

Style Guide

Robert A Fraser edited this page Sep 24, 2020 · 2 revisions

Style Checking

Styling is automatically checked using GLuaFixer - any PRs will need to pass this check before being merged into master. If the checker yells at you, please try and fix it up. If anything is being a particular pain, please let me know and I'll adjust some settings.

GMod Lua

  • Use Lua style operators and or not ~= and not C style operators || && !
  • In weapons, use self instead of self.Weapon and self:GetOwner() instead of self.Owner

Spacing

  • Indentation is four spaces. Not tabs.
  • Don't leave whitespace on blank lines
  • Don't leave trailing whitespace at the end of lines
  • Keep lines a sane length where possible (under 120 columns)
  • Spaces between operators: variable * 5
  • But not after brackets: ply:SetPos(Vector(0, 0, 0))
  • If statements should start a new line, even for short statements:
if coolValue then
    return
end

Naming

  • Use "double quotes" instead of 'single quotes'
  • camelCase is preferred for local variables and functions

General

  • Never use goto
  • Don't build scope pyramids: split things into functions, condense if statements, etc.
  • Don't have unused variables
    • We're using Git - if you rework something we can get the old version back later
    • Unused variables in loops eg. for k,v in pairs(table) are acceptable, but try and avoid this

Functions

  • Don't use global functions unless you have to
    • You probably don't have to use global functions
    • GM: functions are fine
  • Put function bodies on new lines:
hook.Add("MyHook", "Example", function(a)
    print(a)
end)