Skip to content

Instantly share code, notes, and snippets.

@nenodias
Last active September 14, 2017 11:40
Show Gist options
  • Save nenodias/99cf50cf3fc458ca0371ac112fbf0287 to your computer and use it in GitHub Desktop.
Save nenodias/99cf50cf3fc458ca0371ac112fbf0287 to your computer and use it in GitHub Desktop.
Exemplo de código usando Lua
printf = function(s,...)
io.write(s:format(...))
io.write("\n")
end
numero = 18
print(string.format("Hello world %s", numero))
printf("Hello world %s", numero)
printf("--Exemplo If --")
if numero > 10 and numero < 20 then
print( "Número está na faixa" )
end
printf("-- Exemplo If ElseIf Else --")
if numero > 10 then
print( "Número é maior que 10" )
elseif numero > 8 then
print( "Número maior que 8" )
else
print( "Número é menor que ou igual a 10" )
end
cont = 0
printf("--Exemplo While --")
while cont < 10 do
printf("Item %s",cont)
cont = cont + 1
end
printf("--Exemplo For --")
for i = 0,9 do
printf("Item %s",i)
end
-- Objects Examples --
SimpleClass = {}
SimpleClass_mt = { __index = SimpleClass }
-- This function creates a new instance of SimpleClass
--
function SimpleClass:create()
local new_inst = {} -- the new instance
setmetatable( new_inst, SimpleClass_mt ) -- all instances share the same metatable
return new_inst
end
-- Here are some functions (methods) for SimpleClass:
function SimpleClass:className()
print( "SimpleClass" )
end
function SimpleClass:doSomething()
print( "Doing something" )
end
simple = SimpleClass:create()
simple:doSomething()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment