-
Notifications
You must be signed in to change notification settings - Fork 147
coding style (lua)
Artem Popov edited this page Oct 8, 2018
·
5 revisions
this is a work in progress! please add to it, request clarification, point out discrepancies, dispute, &c.
- 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 tofoo = 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)
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
monome.org