User:Ganaram inukshuk/Provisional style guide for Lua: Difference between revisions

Ganaram inukshuk (talk | contribs)
No edit summary
Ganaram inukshuk (talk | contribs)
No edit summary
Line 141: Line 141:
Unless the wrapper functions encapsulate very simple tasks, a module should only ever provide '''one''' wrapper function for '''one''' template.
Unless the wrapper functions encapsulate very simple tasks, a module should only ever provide '''one''' wrapper function for '''one''' template.


==== What to pass ====
If a function's expected inputs is determined to be fixed (that is, no new features are expected to ever be added), the underscore-prefixed function can accept them in sequence.<syntaxhighlight lang="lua">
-- "Main" function to be called by wrapper or another module
function p._call_me(arg1, arg2, arg3)
    -- Code goes here
end
</syntaxhighlight>If a function expects large amounts of input, or if the number of inputs is not known, it should be entered as a table of arguments into the underscore-prefixed function.<syntaxhighlight lang="lua">
-- "Main" function to be called by wrapper or another module
function p._call_me(args)
    -- Get args here
    local args1 = args["args1"]
    local args2 = args["args2"]
    local args3 = args["args3"]
   
    -- Code goes here
end
</syntaxhighlight>
=== Concatenating strings ===
=== Concatenating strings ===


Line 250: Line 267:


=== Param names ===
=== Param names ===
Capitalized, short, and descriptive parameter names are preferred wherever possible, such as <code>Scale Signature</code>, and not <code>scalesig</code> or <code>ssg</code>. Non-capitalized parameter names are used for debugging, testing, or meta-use (parameters used to build other templates and typically would never be seen in normal use), such as <code>name</code> and <code>debug</code>.
Capitalized, short, and descriptive parameter names are preferred wherever possible, such as <code>Scale Signature</code>, and not <code>scalesig</code> or <code>ssg</code>.
 
Non-capitalized parameter names are used for debugging, testing, or meta-use (parameters used to build other templates and typically would never be seen in normal use), such as <code>name</code> and <code>debug</code>. Templates with simple usage can use non-capitalized parameter names throughout.