Lua Programming/whitespace

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 indentation in either the horizontal or vertical directions.

Line Breaks and Indentation

edit

The use of indentation and linebreaks 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 functions and procedures end, and which lines are part of which loops and procedures:

!!Example need here

Whitespace characters are ignored by the interpreter

edit

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

edit

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

edit

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

edit

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