]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/man/man9/style.lua.9
style.lua(9): Note that wrapping at 80-columns is not rigid
[FreeBSD/FreeBSD.git] / share / man / man9 / style.lua.9
1 .\"-
2 .\" Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org>
3 .\" All rights reserved.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\"    notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\"    notice, this list of conditions and the following disclaimer in the
12 .\"    documentation and/or other materials provided with the distribution.
13 .\"
14 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED.  IN NO EVENT SHALL [your name] OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 .\" SUCH DAMAGE.
25 .\"
26 .\" $FreeBSD$
27 .\"
28 .Dd February 19, 2018
29 .Dt STYLE.LUA 9
30 .Os
31 .Sh NAME
32 .Nm style.lua
33 .Nd
34 .Fx
35 lua file style guide
36 .Sh DESCRIPTION
37 This file specifies the preferred style for lua source files in the
38 .Fx
39 source tree.
40 Many of the style rules are implicit in the examples.
41 Be careful to check the examples before assuming that
42 .Nm
43 is silent on an issue.
44 .Pp
45 The copyright header should be a series of single-line comments.
46 Use the single-line comment style for every line in a multi-line comment.
47 .Pp
48 After any copyright header, there is a blank line, and the
49 .Li $\&FreeBSD$
50 comment for non-C/C++ source files.
51 .Pp
52 The preferred method of including other files and modules is with
53 .Fn require name ,
54 such as:
55 .Bd -literal
56 -- $FreeBSD$
57
58 config = require("config");
59 menu = require("menu");
60 password = require("password");
61 -- One blank line following the module require block
62 .Ed
63 .Pp
64 .Fn include
65 is generally avoided.
66 .Pp
67 Indentation and wrapping should match the guidelines provided by
68 .Xr style 9 .
69 Do note that it is ok to wrap much earlier than 80 columns if readability would
70 otherwise suffer.
71 .Pp
72 Statements should be terminated with a semicolon.
73 .Ic end
74 should not be terminated with a semicolon.
75 .Pp
76 Where possible,
77 .Fn s:method ...
78 is preferred to
79 .Fn method s ... .
80 This is applicable to objects with methods.
81 String are a commonly-used example of objects with methods.
82 .Pp
83 Testing for
84 .Va nil
85 should be done explicitly, rather than as a boolean expression.
86 Single-line conditional statements and loops should be avoided.
87 .Pp
88 .Ic local
89 variables should be preferred to module scope variables.
90 .Pp
91 Multiple local variables should not be declared
92 .Sy and
93 initialized on a single line.
94 Lines containing multiple variable declarations without initialization are ok.
95 Lines containing multiple variable declarations initialized to a single function
96 call returning a tuple with the same number of values is also ok.
97 .Pp
98 Initialization
99 .Sy should
100 be done at declaration time as appropriate.
101 .Sh SEE ALSO
102 .Xr style 9
103 .Sh HISTORY
104 This manual page is inspired from the same source as
105 .Xr style 9
106 manual page in
107 .Fx .