This repository has been archived by the owner on Jan 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Lua Style Guide
Gareth YR edited this page Aug 21, 2020
·
6 revisions
local var = "hi" ❌
local var = "hi"; -- ✅
2. Local Variable Names - camelCase
local Var -- ❌
local var -- ✅
local somevar -- ❌
local SomeVar -- ❌
local someVar -- ✅
self.someothervar -- ❌
self.SomeOtherVar -- ❌
self.someOtherVar -- ✅
3. Global Variable Names - PascalCase
var -- ❌
Var -- ✅
someVar -- ❌
somevar -- ❌
Somevar -- ❌
SomeVar -- ✅
4. Function Names - PascalCase
function someFunction() -- ❌
function Somefunction() -- ❌
function somefunction() -- ❌
function some_function() -- ❌
function SomeFunction() -- ✅
Some IDEs have an option to replace tabs with spaces and vice-versa.
Make sure that you are really creating a Tab character when pressing the Tab key!
x=y+z; -- ❌
x = y + z; -- ✅
x=y-z; -- ❌
x = y - z; -- ✅
x=y*z; -- ❌
x = y * z; -- ✅
x=y / z; -- ❌
x = y/z; -- ✅
x=y ^ z; -- ❌
x = y^z; -- ✅
x=a*(y+z); -- ❌
x = a * (y + z); -- ✅
x=y; -- ❌
x = y; -- ✅
function(p1,p2,p3); -- ❌
function(p1, p2, p3); -- ✅
7. Long and Informative Variable Names - as opposed to tons of comments explaining every little thing
toAdd = 5; --This is the number of objects to add per interval -- ❌
numberOfObjectsToAddPerInterval = 5; -- ✅
Comments longer than a few words should be on their own line above the line of code.
local v = 5; -- the v stands for variable -- ❌
local v = 5; --The v stands for variable -- ✅
local v = 5; --The v stands for variable because that's what it is, it's a variable and it's useful to vary things -- ❌
--The v below stands for variable because that's what it is, it's a variable and it's useful to vary things -- ✅
local v = 5;