Code Style Guide

Formatting

Organization

Example

Copy
Style Guide Example
-- An Example Plugin                              -- General information about the plugin/developer at the top
-- by Your Name
-- Month Year

MyAlias = true                                    -- Aliases and global variables are PascalCase
MyObject = {}                                     -- Global Objects are PascalCase

-- Basic commands                                 -- General comments go one line above
Commands = {
  NACK                   = string.char(0x10),     -- Add whitespace to increase readability of large chunks of data
  PingPong               = string.char(0x01),     -- One assignment per line
  AnotherCommand         = string.char(0x20),
  AnEvenLongerCommand    = string.char(0x21),
}

--*** Helper functions ***                        -- Single line comment with asterisks to denote what is contained in this section

-- This function is an example                    -- General comments go on the line above
function MyFunction()                             -- Functions are PascalCase
  local myVariable                                -- Local variables and objects are camelCase
  if MyAlias then                                 -- Single space after operators
    myVariable = false                            
  end
  return myVariable                               -- Indentation for scoping depth is two spaces
end

-- This function is another example
function MyOtherFunction()
  local myString = "" -- A String                 -- Granular comments go in line
  if MyFunction() then
    myString = myString .. "Example"              -- Single space after operators
  end
end