1037f68a9SKyle Evans.\"- 2037f68a9SKyle Evans.\" Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org> 3037f68a9SKyle Evans.\" All rights reserved. 4037f68a9SKyle Evans.\" 5037f68a9SKyle Evans.\" Redistribution and use in source and binary forms, with or without 6037f68a9SKyle Evans.\" modification, are permitted provided that the following conditions 7037f68a9SKyle Evans.\" are met: 8037f68a9SKyle Evans.\" 1. Redistributions of source code must retain the above copyright 9037f68a9SKyle Evans.\" notice, this list of conditions and the following disclaimer. 10037f68a9SKyle Evans.\" 2. Redistributions in binary form must reproduce the above copyright 11037f68a9SKyle Evans.\" notice, this list of conditions and the following disclaimer in the 12037f68a9SKyle Evans.\" documentation and/or other materials provided with the distribution. 13037f68a9SKyle Evans.\" 14037f68a9SKyle Evans.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15037f68a9SKyle Evans.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16037f68a9SKyle Evans.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17037f68a9SKyle Evans.\" ARE DISCLAIMED. IN NO EVENT SHALL [your name] OR CONTRIBUTORS BE LIABLE 18037f68a9SKyle Evans.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19037f68a9SKyle Evans.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20037f68a9SKyle Evans.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21037f68a9SKyle Evans.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22037f68a9SKyle Evans.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23037f68a9SKyle Evans.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24037f68a9SKyle Evans.\" SUCH DAMAGE. 25037f68a9SKyle Evans.\" 26037f68a9SKyle Evans.\" $FreeBSD$ 27037f68a9SKyle Evans.\" 28*e84e7ed5SKyle Evans.Dd February 19, 2018 29037f68a9SKyle Evans.Dt STYLE.LUA 9 30037f68a9SKyle Evans.Os 31037f68a9SKyle Evans.Sh NAME 32037f68a9SKyle Evans.Nm style.lua 33037f68a9SKyle Evans.Nd 34037f68a9SKyle Evans.Fx 35037f68a9SKyle Evanslua file style guide 36037f68a9SKyle Evans.Sh DESCRIPTION 37037f68a9SKyle EvansThis file specifies the preferred style for lua source files in the 38037f68a9SKyle Evans.Fx 39037f68a9SKyle Evanssource tree. 40037f68a9SKyle EvansMany of the style rules are implicit in the examples. 41037f68a9SKyle EvansBe careful to check the examples before assuming that 42037f68a9SKyle Evans.Nm 43037f68a9SKyle Evansis silent on an issue. 44037f68a9SKyle Evans.Pp 45037f68a9SKyle EvansThe copyright header should be a series of single-line comments. 46037f68a9SKyle EvansUse the single-line comment style for every line in a multi-line comment. 47037f68a9SKyle Evans.Pp 48037f68a9SKyle EvansAfter any copyright header, there is a blank line, and the 49037f68a9SKyle Evans.Li $\&FreeBSD$ 50037f68a9SKyle Evanscomment for non-C/C++ source files. 51037f68a9SKyle Evans.Pp 52037f68a9SKyle EvansThe preferred method of including other files and modules is with 53037f68a9SKyle Evans.Fn require name , 54037f68a9SKyle Evanssuch as: 55037f68a9SKyle Evans.Bd -literal 56037f68a9SKyle Evans-- $FreeBSD$ 57037f68a9SKyle Evans 58037f68a9SKyle Evansconfig = require("config"); 59037f68a9SKyle Evansmenu = require("menu"); 60037f68a9SKyle Evanspassword = require("password"); 61037f68a9SKyle Evans-- One blank line following the module require block 62037f68a9SKyle Evans.Ed 63037f68a9SKyle Evans.Pp 64037f68a9SKyle Evans.Fn include 65037f68a9SKyle Evansis generally avoided. 66037f68a9SKyle Evans.Pp 67037f68a9SKyle EvansIndentation and wrapping should match the guidelines provided by 68037f68a9SKyle Evans.Xr style 9 . 69*e84e7ed5SKyle EvansDo note that it is ok to wrap much earlier than 80 columns if readability would 70*e84e7ed5SKyle Evansotherwise suffer. 71037f68a9SKyle Evans.Pp 72037f68a9SKyle EvansStatements should be terminated with a semicolon. 73037f68a9SKyle Evans.Ic end 74037f68a9SKyle Evansshould not be terminated with a semicolon. 75037f68a9SKyle Evans.Pp 76037f68a9SKyle EvansWhere possible, 77037f68a9SKyle Evans.Fn s:method ... 78037f68a9SKyle Evansis preferred to 79037f68a9SKyle Evans.Fn method s ... . 80037f68a9SKyle EvansThis is applicable to objects with methods. 81037f68a9SKyle EvansString are a commonly-used example of objects with methods. 82037f68a9SKyle Evans.Pp 83037f68a9SKyle EvansTesting for 84037f68a9SKyle Evans.Va nil 85037f68a9SKyle Evansshould be done explicitly, rather than as a boolean expression. 86037f68a9SKyle EvansSingle-line conditional statements and loops should be avoided. 87037f68a9SKyle Evans.Pp 88037f68a9SKyle Evans.Ic local 89037f68a9SKyle Evansvariables should be preferred to module scope variables. 90037f68a9SKyle Evans.Pp 91037f68a9SKyle EvansMultiple local variables should not be declared 92037f68a9SKyle Evans.Sy and 93037f68a9SKyle Evansinitialized on a single line. 94037f68a9SKyle EvansLines containing multiple variable declarations without initialization are ok. 95037f68a9SKyle EvansLines containing multiple variable declarations initialized to a single function 96037f68a9SKyle Evanscall returning a tuple with the same number of values is also ok. 97037f68a9SKyle Evans.Pp 98037f68a9SKyle EvansInitialization 99037f68a9SKyle Evans.Sy should 100037f68a9SKyle Evansbe done at declaration time as appropriate. 101037f68a9SKyle Evans.Sh SEE ALSO 102037f68a9SKyle Evans.Xr style 9 103037f68a9SKyle Evans.Sh HISTORY 104037f68a9SKyle EvansThis manual page is inspired from the same source as 105037f68a9SKyle Evans.Xr style 9 106037f68a9SKyle Evansmanual page in 107037f68a9SKyle Evans.Fx . 108