[, (, {
and their matches).-- Yes: hi = {1, 2, 3} foo(hi[1], blah['a']) -- No: hi = { 1, 2, 3 } foo( hi[ 1 ], blah[ 'a' ] ) blah ['b'] = hi [3] foo (0, '')
Putting multiple statements on one line is discouraged, unless the expression is very short. Try to avoid this with multi-clause statements, too.
-- Yes: if 1 then foo() bar() else baz() end if 1 then foo() end foo(); bar(); baz(); -- No: if 1 then foo(); bar(); else baz(); end if 1 then foo(); bar(); baz(); else lorem(); ipsum(); end foo(); bar(); baz(); spam(); eggs(); lorem(); ipsum(); dolor(); sit(); amet();
If a single line would be too long, you can split a large statement over multiple lines with a hanging indent that aligns with the opening delimiter. For if
statements, the conditions should be placed on the next line.
-- Example: hello = long_function_name(var_one, var_two, var_three, var_four) if ((condition1 or condition2) and condition3 and condition4) then foo() bar() baz() endNaming conventions[edit]
Define the entry method as simply unpacking the parameters from the frame, and then passing those through a function with the same name prefixed with a single underscore. This can be disregarded if the function is only useful from wikitext, or if it needs a frame for something other than its arguments.
In the standard library, function names consisting of multiple words are simply put together (e.g. setmetatable
). Note that camelCase is the preferred way to name functions, in order to avoid potential garden-path function names.
-- See https://en.wikipedia.org/w/index.php?oldid=540791109 for code local p = {} function p._url(url, text) -- Code goes here end function p.url(frame) -- Take parameters out of the frame and pass them to p._url(). Return the result. -- Adapt the below code to your specific template arguments local templateArgs = frame.args local url = templateArgs[1] or '' local text = templateArgs[2] or '' return p._url(url, text) end return pHighlighting Lua code[edit]
Outside of a module (like on talkpages), code highlighting can be added using the <syntaxhighlight> tag with the attribute lang="lua"
:
--code snippet function p.main() return "Hello world" end</syntaxhighlight>
Produces:
--code snippet function p.main() return "Hello world" end
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4