apresentação sobre a linguagem lua
DESCRIPTION
Apresentação de Slides feita pelos alunos Rafael e Rogers sobre a linguagem de programação Lua !!!TRANSCRIPT
![Page 1: Apresentação sobre a linguagem lua](https://reader035.vdocuments.pub/reader035/viewer/2022062319/5562ca44d8b42a09618b5a26/html5/thumbnails/1.jpg)
LABORATÓRIO DE PESQUISA E INOVAÇÃO
EM TECNOLOGIAS
E ESTRATÉGIAS
DE AUTOMAÇÃO
TEAR
Particularidades e aplicações
Rafael Sanches & Rogers CristoProf. Dr. Antonio Francisco do Prado
![Page 2: Apresentação sobre a linguagem lua](https://reader035.vdocuments.pub/reader035/viewer/2022062319/5562ca44d8b42a09618b5a26/html5/thumbnails/2.jpg)
2
ÍNDICE
• História da Linguagem
• Paradigmas suportados
• Sintaxe da Linguagem
• Aplicações da Linguagem
• Conclusão
• Referências Bibliográficas
![Page 3: Apresentação sobre a linguagem lua](https://reader035.vdocuments.pub/reader035/viewer/2022062319/5562ca44d8b42a09618b5a26/html5/thumbnails/3.jpg)
HISTÓRIA
3
1992: Tecgraf - projeto entre PUC e PETROBRAS (CENPES) Roberto Ierusalimschy, Luiz H. de Figueiredo, Waldemar Celes Construção de interfaces gráficas para diversos programas de simulação 1993: Projeto com a PETROBRAS programa para visualização de perfis
geológicos configurável
![Page 4: Apresentação sobre a linguagem lua](https://reader035.vdocuments.pub/reader035/viewer/2022062319/5562ca44d8b42a09618b5a26/html5/thumbnails/4.jpg)
SINTAXE DA LINGUAGEM
4
• Tipos de dados
Nil – Vazio = a = nil Number – a = 3 ou a = 3.5 ele assume tanto inteiros quanto flutuantes String – texto = “Cadeia de Caracteres” ou texto2 = [[Programacao Lua]] Table – Unica estrutura de dados assumida pela Linguagem == Array
Associativo UserData - É usado para representar objetos externos a Lua (e.g., arquivos). Function - foo = function { print(“Tipo Função”) } pode ou não ter retorno Boolean – True ou False == Verdadeiro ou Falso Coroutines – Threads em Lua
![Page 5: Apresentação sobre a linguagem lua](https://reader035.vdocuments.pub/reader035/viewer/2022062319/5562ca44d8b42a09618b5a26/html5/thumbnails/5.jpg)
5
PARADIGMAS SUPORTADOS
Scripting Imperativo
Funcional Orientado a Objetos
![Page 6: Apresentação sobre a linguagem lua](https://reader035.vdocuments.pub/reader035/viewer/2022062319/5562ca44d8b42a09618b5a26/html5/thumbnails/6.jpg)
6
SINTAXE DA LINGUAGEM
IF THEN ELSE
if expr then bloco end
if exp then bloco1... else bloco2... end
OR OR
if expr1 then bloco1 elseif expr2 then bloco2 ... elseif expr N then bloco N else bloco N+1 end
• Comandos de controle
![Page 7: Apresentação sobre a linguagem lua](https://reader035.vdocuments.pub/reader035/viewer/2022062319/5562ca44d8b42a09618b5a26/html5/thumbnails/7.jpg)
SINTAXE DA LINGUAGEM
7
• Comandos de controle
WHILE FOR
Tomadas de decisão no início
while expr do bloco end
f = 1 --valor do fatorial i = n --controle do laço while i > 0 do f = f * i i = i – 1 end
for var=init, limit do--blocoend
for var in list do--bloco1end
for key,value in ipairs(table) do--bloco2end
for var=init, limit, range do--bloco3 o range e o intervalo--da passagem exe 1..3..5..7end
repeat--blocountil exp
REPEAT
Tomadas de decisão no fim
f = 1 --valor do fatorial i = 1 --controle do laço repeat f = f * i i = i + 1 until i > n
![Page 8: Apresentação sobre a linguagem lua](https://reader035.vdocuments.pub/reader035/viewer/2022062319/5562ca44d8b42a09618b5a26/html5/thumbnails/8.jpg)
8
SINTAXE DA LINGUAGEM
Matrizes
vet = { {}, {}, {} }vet[1][1] = 4vet[1][2] = 34.5
Objetos
obj = {}obj.atrib1 = 4obj.met1 = f
Records
strut = {}strut.campo = valorstrut.outro = 2.3
Vetores
vet = {}vet[1] = 2.3vet[2] = 3.45vet[3] = 5.0
Tabelas
t = {}t[‘nome’] = “Teste”
print(t.nome)
![Page 9: Apresentação sobre a linguagem lua](https://reader035.vdocuments.pub/reader035/viewer/2022062319/5562ca44d8b42a09618b5a26/html5/thumbnails/9.jpg)
SINTAXE DA LINGUAGEM
9
• Criação de Funções
function name(p1,p2,p3) local x = p1 local y = p2 local z = p3end
function name(parameters) return end
function teste() return 10,20 endx,y = teste()print("X = "..x.." Y = "..y)
Lua ainda tem a vantagem de atribuição múltipla e retorno múltiplo Funções são criadas dinamicamente
Sintaxe function (<pars>) <body> end
Cria uma nova função Equivalente a notação (lambda (<pars) <body>) da linguagem Scheme Esta é uma abstração no λ -cálculo.
![Page 10: Apresentação sobre a linguagem lua](https://reader035.vdocuments.pub/reader035/viewer/2022062319/5562ca44d8b42a09618b5a26/html5/thumbnails/10.jpg)
SINTAXE DA LINGUAGEM
10
• Paradigma Funcional Lua não é uma linguagem puramente funcional Funções definidas pelo programador como: cons, head, tail e empty
(semântica similar as presentes em outras linguagens funcionais), que operam sobre tabelas.
local lista = cons ( 3 , cons (2 , cons (1 , Nil ) ) ) -- 1, 2 , 3
print ( lista ) -- (1 2 3)
print ( head ( lista ) ) -- 1
print ( tail ( lista ) ) -- (2 3)
print ( empty ( lista ) ) -- (false)
print ( lista ) -- (1 2 3), lista e :imutável
![Page 11: Apresentação sobre a linguagem lua](https://reader035.vdocuments.pub/reader035/viewer/2022062319/5562ca44d8b42a09618b5a26/html5/thumbnails/11.jpg)
SINTAXE DA LINGUAGEM
11
• Paradigma Orientado a Objetos Também se vale da combinação de tabelas com funções de primeira classe. Em Lua, um objeto é meramente uma tabela, contendo campos com seus
dados (variáveis de instância) e operações (métodos).
Rectangle = {x = 0, y = 0, width = 10, height = 20}
Rectangle.__index = Rectangle
function Rectangle:new (objeto) setmetatable(objeto, self) return objetoend
function Rectangle:area () return self.width * self.heightend
r = Rectangle:new{width = 40, height = 60}
print(r:area()) → 2400
![Page 12: Apresentação sobre a linguagem lua](https://reader035.vdocuments.pub/reader035/viewer/2022062319/5562ca44d8b42a09618b5a26/html5/thumbnails/12.jpg)
SINTAXE DA LINGUAGEM
12
• Paradigma Concorrente Cada co-rotina em Lua representa uma linha de execução independente com
sua própria pilha de chamadas. Bastante similares a linhas de execução (threads) cooperativas.
co = coroutine.wrap(function (x) print(x) coroutine.yield()--da um time aqui print(2*x) coroutine.yield()--da um time aqui print(10*x) end)
co(20)--ela para no yieldco()--ela continua de onde parou a execução anterior co()
coroutine.create(f)
coroutine.wrap(f,corpo)
coroutine.resume(co,argumentos)
coroutine.running()
coroutine.status(f)
coroutine.yield(sim,nao)
![Page 13: Apresentação sobre a linguagem lua](https://reader035.vdocuments.pub/reader035/viewer/2022062319/5562ca44d8b42a09618b5a26/html5/thumbnails/13.jpg)
SINTAXE DA LINGUAGEM
13
• User Data – Lua “Embarcada”
Lua foi projetada para se comunicar com C.
Uma distinção útil é entre embutir (embed) e estender uma linguagem de script.
Embutir é usar a linguagem como uma biblioteca C dentro de um programa hospedeiro.
Enquanto estender é escrever o programa principal na linguagem dinâmica estendida com funções escritas em C.
![Page 14: Apresentação sobre a linguagem lua](https://reader035.vdocuments.pub/reader035/viewer/2022062319/5562ca44d8b42a09618b5a26/html5/thumbnails/14.jpg)
SINTAXE DA LINGUAGEM
14
• User Data – Lua “Embarcada”
Estendendo Lua.
#include "lua.h“#include "lauxlib.h“
int main (int argc, char **argv) { lua_State *L = luaL_newstate();
if (luaL_loadfile(L, argv[1]) != LUA_OK) fprintf(stderr, "error: %s\n", lua_tostring(L, -1)); else if (lua_pcall(L, 0, 0, 0) != LUA_OK) fprintf(stderr, "error: %s\n", lua_tostring(L, -1));
else { lua_getglobal(L, "result"); printf("resultado: %f\n", lua_tonumber(L, -1)); }
lua_close(L);return 0;}
![Page 15: Apresentação sobre a linguagem lua](https://reader035.vdocuments.pub/reader035/viewer/2022062319/5562ca44d8b42a09618b5a26/html5/thumbnails/15.jpg)
APLICAÇÕES DA LINGUAGEM
15
![Page 16: Apresentação sobre a linguagem lua](https://reader035.vdocuments.pub/reader035/viewer/2022062319/5562ca44d8b42a09618b5a26/html5/thumbnails/16.jpg)
APLICAÇÕES DA LINGUAGEM
16
Abrangência: chegou a possuir mais de 12 milhões de jogadores ativos.
Lua é utilizado em modificações de UI.
Abrangência: em 2012 bateu o número de 1 bilhão de downloads.
Lua é utilizado em conjunto com Objective-C nas aplicações específicas de iOS.
Abrangência: possui atualmente 450 milhões de usuários.
Lua é a principal linguagem, junto com Javascript, utilizada nas famosas extensões do browser.
![Page 17: Apresentação sobre a linguagem lua](https://reader035.vdocuments.pub/reader035/viewer/2022062319/5562ca44d8b42a09618b5a26/html5/thumbnails/17.jpg)
APLICAÇÕES DA LINGUAGEM
17
• Outras aplicações - Projetos
Celestia Cheat Engine ClanLib CryEngine 3
Corona SDK Damn Small Linux Ginga Kepler (software) lighttpd Liquid Feedback MinGW Monotone Nmap PlayStation Home
![Page 18: Apresentação sobre a linguagem lua](https://reader035.vdocuments.pub/reader035/viewer/2022062319/5562ca44d8b42a09618b5a26/html5/thumbnails/18.jpg)
APLICAÇÕES DA LINGUAGEM
18
• Outras aplicações - Games
Baldur's Gate The Battle for Wesnoth Civilization V Escape from Monkey Island Fable II Far Cry FlyFF Freeciv Freelancer Grim Fandango Impossible Creatures Lego Universe
MapleStory MDK2 Monopoly Tycoon Multi Theft Auto Psychonauts2 Ragnarok Online Roblox Tibia
![Page 19: Apresentação sobre a linguagem lua](https://reader035.vdocuments.pub/reader035/viewer/2022062319/5562ca44d8b42a09618b5a26/html5/thumbnails/19.jpg)
APLICAÇÕES DA LINGUAGEM
19
EXEMPLO DE JOGO
![Page 20: Apresentação sobre a linguagem lua](https://reader035.vdocuments.pub/reader035/viewer/2022062319/5562ca44d8b42a09618b5a26/html5/thumbnails/20.jpg)
APLICAÇÕES DA LINGUAGEM
20
• Aplicações recentes Tecgraf/Petrobras
![Page 21: Apresentação sobre a linguagem lua](https://reader035.vdocuments.pub/reader035/viewer/2022062319/5562ca44d8b42a09618b5a26/html5/thumbnails/21.jpg)
APLICAÇÕES DA LINGUAGEM
21
• Aplicação em TV Digital
A PUC-Rio continua o desenvolvimento da linguagem LUA Foco em programas interativos para TV Digital Mais informações: http://www.telemidia.puc-rio.br/
![Page 22: Apresentação sobre a linguagem lua](https://reader035.vdocuments.pub/reader035/viewer/2022062319/5562ca44d8b42a09618b5a26/html5/thumbnails/22.jpg)
CONCLUSÃO
22
• Por que escolher Lua?
Lua é linguagem estabelecida e robusta.
Lua é rápida.
Lua é portátil e embutível.
Lua é simples pequena.
Lua é poderosa.
Lua é opensource. Lua é BRASILEIRO!
![Page 23: Apresentação sobre a linguagem lua](https://reader035.vdocuments.pub/reader035/viewer/2022062319/5562ca44d8b42a09618b5a26/html5/thumbnails/23.jpg)
REFERÊNCIAS
23
http://www.lua.org/ http://www.tecgraf.puc-rio.br/ http://coronalabs.com/ http://www.telemidia.puc-rio.br/
![Page 24: Apresentação sobre a linguagem lua](https://reader035.vdocuments.pub/reader035/viewer/2022062319/5562ca44d8b42a09618b5a26/html5/thumbnails/24.jpg)
www.tear.dc.ufscar.br
OBRIGADO!