-
Notifications
You must be signed in to change notification settings - Fork 5
Style Guide
Robert A Fraser edited this page Sep 24, 2020
·
2 revisions
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.
- Use Lua style operators
and or not ~=
and not C style operators|| && !
- In weapons, use
self
instead ofself.Weapon
andself:GetOwner()
instead ofself.Owner
- 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
- Use
"double quotes"
instead of'single quotes'
-
camelCase
is preferred for local variables and functions
- 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
- 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)
Getting Started Pages:
| Server Hosting
| Mapping
| Lua Development
|