Skip to content
Immemor edited this page May 12, 2015 · 5 revisions

Coding style

Every file, must start with this header:

----------------------------------------------------------------------------------------------------
-- Client Lua Script for RaidCore Addon on WildStar Game.
--
-- Copyright (C) 2015 RaidCore
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
--
--  Feature description contain in this file.
--
----------------------------------------------------------------------------------------------------

All constants should be near the beginning of the file, and declaration should be in upper case. example:

-- MY is beautiful constant.
local MY_CONSTANT = "Avatus"
local BUFFID_AVATUS_MOREPOWER = 123456

As a global example is better than a long discour, so:

local _bTrigged = false

function MyClass:IsEnable(tGreatArray, bEnable)
    if bEnable then
        for _, entry in next, tGreatArray do
            local sName = entry.name
            if not _bTrigged and MY_CONSTANT == sName then
                -- Don't print a second time.
                _bTrigged = true
                Print("Hello World")
            end
         end
    end
end

Few remarks from this example:

  • 4 spaces are used,
  • Line length shouldn't be bigger than 100 char,
  • Avoid to jump 2 empty lines,
  • To match with Carbine Style, CapitalizedWords will be used as naming style.
  • Variables are prefix with 's', 'b', 'n', 'f', or 't' for the type indication 'string', 'boolean', 'numeric', 'function', or 'table'.
  • Every comment is a sentence, so don't forget the upper case on the first letter of the first word, and don't forget the dot at the end.
  • If the variable is local to the file, an underscore will be added in as prefix also.

In case of doubt, and if you have time, you can read the PEP8. But it's a little bit huge. Ref: https://www.python.org/dev/peps/pep-0008/

Clone this wiki locally