better conventions

This commit is contained in:
petrucci4prez 2017-07-16 13:49:43 -04:00
parent 0ed2b3d5c5
commit 8275b64a2a
1 changed files with 53 additions and 10 deletions

View File

@ -1,16 +1,59 @@
--[[ --[[
Conventions: Boolean conventions:
0 is true, 1 is false 0 is true, 1 is false
Module format:
LIBRARY STRUCTURE (a collection of functions/values in a table):
local M = {} -- define module-level table to return
local modname = requires 'modname'
-- import all required modules
local foo = function()
-- code
end
-- define more functions
M.foo = foo -- dump all functions into table
return M -- return entire table (use functions as modname.foo)
RENDERING MODULE STRUCTURE (only used in this module; main.lua):
local modname = requires 'modname'
-- import all required modules
local foo = function()
-- code
end
local draw = function(args)
-- drawing code that uses foo()
end
return draw -- only draw is returned (use as modname(args))
Var names: Var names:
- Scope: - delimiters: all words separated by _ (unless camalCase)
- local: no underscore - booleans: preceed by is_ (as in is_awesome)
- module: single underscore - Spacial scope:
- global: double underscore - Everything declared local by default
- required (imported): no underscore (same name as file) - reassigning to local:
- Mutability - upval to local: preceed with _
- variable: lowercase - global to local: preceed with __
- constant: all caps - replace . with _ if callng from table
- global: preceed with g_
- Temporal Scope
- init: only relevent to startup (nil'ed before first rendering loop)
- persistant: always relevent (potentially)
- init vars end with _
- Mutability
- variable: lowercase
- constant: ALL_CAPS
- constants can be anything except functions
- Module Names:
- CapCamalCase
- var name is exactly the same as module name
--]] --]]
local ABS_PATH = os.getenv('CONKY_LUA_HOME') local ABS_PATH = os.getenv('CONKY_LUA_HOME')