Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Lua
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Syntax === The classic [["Hello, World!" program]] can be written as follows, with or without parentheses:<ref>{{cite web |url=https://www.lua.org/pil/1.html |title=Programming in Lua : 1}}</ref>{{efn|Syntactic sugar, a table construct or literal string following an identifier is a valid function call.<ref>{{cite web |url=https://www.lua.org/manual/5.0/manual.html#2.5.7 |title=Lua 5.0 Reference Manual, 2.5.7, Function Calls}}</ref>}} <syntaxhighlight lang="lua"> print("Hello, World!") </syntaxhighlight> <syntaxhighlight lang="lua"> print "Hello, World!" </syntaxhighlight> The declaration of a variable, without a value. <syntaxhighlight lang="lua"> local variable </syntaxhighlight> The declaration of a variable with a value of 10. <syntaxhighlight lang="lua"> local students = 10 </syntaxhighlight> A [[Comment (computer programming)|comment]] in Lua starts with a double-hyphen and runs to the end of the line, similar to [[Ada (programming language)|Ada]], [[Eiffel (programming language)|Eiffel]], [[Haskell]], [[SQL]] and [[VHDL]]. Multi-line strings and comments are marked with double square brackets. <syntaxhighlight lang="lua"> -- Single line comment --[[ Multi-line comment --]] </syntaxhighlight> {{anchor|Factorial example}}The [[factorial]] function is implemented in this example:<!-- referred to elsewhere in this article --> <syntaxhighlight lang="lua"> function factorial(n) local x = 1 for i = 2, n do x = x * i end return x end </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)