STYLE.LUA(9)
π¦ NAME π¦
style.lua β bestie, this is the FreeBSD lua file style guide. Yep, the STYLE.LUA(9) page from the Kernel Developer's Manual. Buckle up, we're making your lua source files look iconic. π
πΈ DESCRIPTION πΈ
Okay so this file specifies the preferred style for lua source files in the FreeBSD source tree. Many of the style rules are lowkey implicit in the examples β so before you assume style.lua is silent on an issue, pls check the examples first. Non-negotiable vibe check. π
- 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.
- Including other files and modules β the preferred method is
require(name), such as:
-- License block
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 tomethod(s, ...). This is applicable to objects with methods. Strings are a commonly-used example of objects with methods. π - Testing for
nilshould be done explicitly, rather than as a boolean expression. Single-line conditional statements and loops should be avoided. Ngl, fr fr. localvariables should be preferred to global variables in module scope.internal_underscorestend to be preferred for variable identifiers, whilecamelCasetends 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. Obsessed with safety. π«Ά
- Multiple
localvariables should not be declared and initialized on a single line. Lines containing multiple variable declarations without initialization are ok. Lines containing multiple variable declarations initialized 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. Main character energy for declarations. π
π«Ά SEE ALSO π«Ά
style(9)β yes bestie, go read it. It's giving sibling energy. π
π HISTORY π
This manual page is inspired from the same source as the style(9) manual page in FreeBSD.
π cute sign-off: the source is Debian, the date is February 25, 2018, and the manual is STYLE.LUA(9). periodt. π
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- π the page's license: BSD-2-Clause
- Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms