Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
STYLE.LUA(9)	       FreeBSD Kernel Developer's Manual	  STYLE.LUA(9)

NAME
     style.lua -- FreeBSD lua file style guide

DESCRIPTION
     This file specifies the preferred style for lua source files in the
     FreeBSD source tree.  Many	of the style rules are implicit	in the exam-
     ples.  Be careful to check	the examples before assuming that style.lua is
     silent on an issue.

     The copyright header should be a series of	single-line comments.  Use the
     single-line comment style for every line in a multi-line comment.

     After any copyright header, there is a blank line,	and the	$FreeBSD$ com-
     ment for non-C/C++	source files.

     The preferred method of including other files and modules is with
     require(name), such as:

     --	$FreeBSD: stable/12/share/man/man9/style.lua.9 333419 2018-05-09 16:52:28Z kevans $

     config = require("config");
     menu = require("menu");
     password =	require("password");
     --	One blank line following the module require block

     include() is generally avoided.

     Indentation and wrapping should match the guidelines provided by
     style(9).	Do note	that it	is ok to wrap much earlier than	80 columns if
     readability would otherwise suffer.

     Where possible, s:method(...)  is preferred to method(s, ...).  This is
     applicable	to objects with	methods.  String are a commonly-used example
     of	objects	with methods.

     Testing for nil should be done explicitly,	rather than as a boolean ex-
     pression.	Single-line conditional	statements and loops should be
     avoided.

     local variables should be preferred to global variables in	module scope.
     internal_underscores tend to be preferred for variable identifiers, while
     camelCase tends to	be preferred for function identifiers.

     If	a table	definition spans multiple lines, then the final	value in the
     table should include the optional terminating comma.  For example:

     --	No terminating comma needed for	trivial	table definitions
     local trivial_table = {1, 2, 3, 4}

     local complex_table = {
	     {
		     id	= "foo",
		     func = foo_function, -- Trailing comma preferred
	     },
	     {
		     id	= "bar",
		     func = bar_function,
	     },	     --	Trailing comma preferred
     }

     This reduces the chance for errors	to be introduced when modifying	more
     complex tables.

     Multiple local variables should not be declared and initialized on	a sin-
     gle line.	Lines containing multiple variable declarations	without	ini-
     tialization are ok.  Lines	containing multiple variable declarations ini-
     tialized to a single function call	returning a tuple with the same	number
     of	values is also ok.

     Initialization should be done at declaration time as appropriate.

SEE ALSO
     style(9)

HISTORY
     This manual page is inspired from the same	source as style(9) manual page
     in	FreeBSD.

FreeBSD	13.0		       February	25, 2018		  FreeBSD 13.0

NAME | DESCRIPTION | SEE ALSO | HISTORY

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=style.lua&sektion=9&manpath=FreeBSD+12.1-RELEASE>

home | help