Skip to content

Latest commit

 

History

History
71 lines (62 loc) · 1.94 KB

CodingConvention.md

File metadata and controls

71 lines (62 loc) · 1.94 KB

Coding Convention

This is the convention that we agreed to use on this project.
This is not yet fixed, it may change if we see fit until the first release.

LUA FILE RETURN

Not everything is global, your file can return an object and be required into a variable where it is needed.

local obj = {}
function obj.DoSomething() end
return obj

REQUIRE

Usage of require in LUA scripts to ensure dependency is loaded first or to get an object returned by an other file.

require("path_to_required_file")
local required_object = require("path_to_required_object")
-- path start after 'media/lua/client/'
-- path start after 'media/lua/server/'
-- path start after 'media/lua/shared/'
-- path end without file extention

GLOBAL

GLOBAL_VAR = "" -- UpperCase
function GlobalFunc() end -- PascalCase

LOCAL

local someVariable = "" -- camelCase
local function someFunction() end -- camelCase

OBJECT

local MyObject = {} -- PascalCase
function MyObject.StaticMethod() end -- PascalCase 
function MyObject:instanceMethod() end -- camelCase

PARAMETERS

local function func(requiredParam) end -- camelCase
local function func(_optionalParam) end -- camelCase prefixed with underscore

MULTI PARAMETERS

Separate parameters with a space after the comma.

-- Wrong
function(param1,param2)
-- Good
function(param1, param2)

ANNOTATIONS

Annotations are important for making your code understandable, it also allows IDE intelisense with Emmylua plugin to auto-complete and visualize globals, locals, functions and parameters.

---@class MyClass Description of the class
local MyClass = {}

--- Short description of the usage of this method
---@param param1 string   Description of this parameter
---@return string
function MyClass:setName(param1)
    return param1
end

View Emmylua docs for more information about annotations.