Lua Style Guide - cortex-command-community/Cortex-Command-Community-Project GitHub Wiki

All lua changes will reviewed according to this style guide!

Save yourself and the reviewer(s) some time and adhere to this please.

 

1. Line Endings - Always end with a semicolon

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()	 -- ✅

5. Tabbing vs. Spaces - Use tabs!

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!

6. Spacing Around Symbols (, == = + - * / ^) - Spaced out except for / and ^

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; -- ✅

8. Commenting Style - No space after -- and start comment with capital letter

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;