Lua Style Guide

From Legacy Roblox Wiki
Revision as of 09:47, 7 August 2011 by >NXTBoy (We need one of these.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Casing Rules

lowerCamelCase

local variables, functions, and function arguments should be named in lowerCamelCase.

Right
part, myModel, myFunction, i, transparency
Wrong
Part, MyModel, myFunction, I, Transparency
Example
function myFunction(a, b)
    return a*2 + b
end

UpperCamelCase (PascalCase)

Class names, such as Vector2, and MyBetterVector, should be in PascalCase.

Whitespace Rules

Indentation

Each level of block shouold be indented by a single tab.

Expressions

Spaces are optional around * and /. If there is one after, always put one before, and vice versa. Always include spaces before and after =, and all the other binary operators. Unary operators, such as -a and #a should not have a space between the operator and the operand.

Right:
local a = (b + #t)*c
local b = -a + 3*(c - a) / 2
print(b == a)
Wrong:
local a =(b+c)* d
local b= -a+3*(c-a)/2
print(b==a)

Commas

Never put a space before a comma, but multiple spaces may come after.