lua example
Example 1: lua function
--
function PrintingText()
print("My text here")
end
PrintingText()
Example 2: how to say hi in lua
print("hello")
Example 3: lua functions
function myFunction() -- Start with 'function', give it a name
-- Do something amazing...
end -- Finish with 'end'
myFunction() -- Call the function later in the code
Example 4: What is lua used for
Lua is a powerful and fast programming language that is easy to
learn and use and to embed into your application.
Lua is designed to be a lightweight embeddable scripting language.
It is used for all sorts of applications,
from games to web applications and image processing.
--
Used commonly in Roblox, Garry's Mod and Multi Theft Auto
Example 5: how to lua
-- Well, first, you could make a variable
local variable = true
-- If you want to print something in the output
print("Hello Output!")
-- Finally, the rest is up to you.
Example 6: lua syntax
chunk ::= {stat [`;´]} [laststat [`;´]]
block ::= chunk
stat ::= varlist `=´ explist |
functioncall |
do block end |
while exp do block end |
repeat block until exp |
if exp then block {elseif exp then block} [else block] end |
for Name `=´ exp `,´ exp [`,´ exp] do block end |
for namelist in explist do block end |
function funcname funcbody |
local function Name funcbody |
local namelist [`=´ explist]
laststat ::= return [explist] | break
funcname ::= Name {`.´ Name} [`:´ Name]
varlist ::= var {`,´ var}
var ::= Name | prefixexp `[´ exp `]´ | prefixexp `.´ Name
namelist ::= Name {`,´ Name}
explist ::= {exp `,´} exp
exp ::= nil | false | true | Number | String | `...´ | function |
prefixexp | tableconstructor | exp binop exp | unop exp
prefixexp ::= var | functioncall | `(´ exp `)´
functioncall ::= prefixexp args | prefixexp `:´ Name args
args ::= `(´ [explist] `)´ | tableconstructor | String
function ::= function funcbody
funcbody ::= `(´ [parlist] `)´ block end
parlist ::= namelist [`,´ `...´] | `...´
tableconstructor ::= `{´ [fieldlist] `}´
fieldlist ::= field {fieldsep field} [fieldsep]
field ::= `[´ exp `]´ `=´ exp | Name `=´ exp | exp
fieldsep ::= `,´ | `;´
binop ::= `+´ | `-´ | `*´ | `/´ | `^´ | `%´ | `..´ |
`<´ | `<=´ | `>´ | `>=´ | `==´ | `~=´ |
and | or
unop ::= `-´ | not | `#´