411 REFERENCE · Wikibooks
Lua Programming/whitespace
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
The lua programming language uses a /freeform/ syntax. This means that whitespace characters, such as /space/, /tab/ characters and /newline/ characters can be inserted into the program code for the purpose of spacing, alignment or /indent/ation in either the horizontal or vertical directions.
Line Breaks and Indentation
The use of /indent/ation and /linebreak/s can greatly improve the readability of the code, without affecting the way that the code performs. Using whitespace appropriately, makes the code easier to read and follow because at a glance it is very apparent where /function/s and /procedure/s end, and which lines are part of which /loop/s and /procedure/s:
!!Example need here
Whitespace characters are ignored by the interpreter
The whitespace characters do not change the functionality of the code, and are ignored by the lua interpreter. The following lines of code /execute/ as a single /statement/:
print
"hello"
Strings
As with other programming languages, /space/, /tab/, and /newline/ characters within a quoted /literal string/ do not form whitespace, and are treated as part of the /string/:
print "hello bob"
Line breaks are not permitted within a literal string
In lua, a line break is not permitted within a /literal string/:
-- This will produce an unfinished string error
print "hello
bob"
The LUA language does not contain any spaces as the computer does not know how to read them, but yes there are other ways to communicate spaces without using spaces.
Whitespace is not permitted within an identifier name
It is not permissible to use whitespace in identifier names used for variables or functions:
-- function names cannot contain whitespace
function my function(myparameter)
end
It is permissible to use underscore symbols in identifier names:
function my_function(myparameter)
end