Lua: Syntax

From Mario Fan Games Galaxy Wiki
Revision as of 02:32, 18 May 2009 by Xgoff (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Lua
Lua.gif
Basics
Intermediate
Advanced
XLua
Add to this template
 Standardwikimessagebox.png This article assumes the use of Lua 5.1.

Information may not be accurate or may need revision if you are using a different version.

 Standardwikimessagebox.png This page should be syntax highlighted

Code on this page would be more readable and may wrap correctly if it were surrounded by <source> tags using the enclose="div" attribute.


 Stub.png This article or section is in need of expansion.

Please add further information.

Lua's syntax is quite simple; given its small feature set compared to other languages, it has a much smaller collection of syntax elements. However, much of what it does have is not much different than other languages.

Chunks and Blocks

A chunk is basically a group of statements. A block is much the same thing, but is surrounded by special keywords that are like curly brackets in other languages. One of these is end, which closes all blocks, and the word beginning a block may vary depending on what the block does. for, do, if, and function are common, though there are a few others. One such block may look like:

do
  print("Hello World")
end

do blocks are useful as they can be used to limit the scope of local variables; local variables will only be visible within that block.