You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Artem Popov edited this page Oct 8, 2018
·
5 revisions
lua style guide
this is a work in progress! please add to it, request clarification, point out discrepancies, dispute, &c.
formatting
2-space indentation
double quotes for strings
snake_case for variables, modules and functions
capitalized names for metatables representing classes: ParamSet, ControlSpec, Control
function foo() is preferred to foo = function()
use colon operator as separator for instance methods (Midi:event)
use dot as separator for class methods (Midi.add)
separate function arguments with a comma and a space: foo(a, b, c)
local variables
use local variables and functions where possible. a script shouldn't declare global variables, for example:
local tab = require 'tabutil' -- good
pattern_time = require 'pattern_time -- bad
-- bad
baz = "module-scoped variable"
function foo()
bar = 1
print(bar, baz)
end
-- good
local baz = "module-scoped variable"
local function foo()
local bar = 1
print(bar, baz)
end