Lua
Vikipediya, açıq ensiklopediya
| Paradiqma: | Funksional, obyekt yönümlü |
| Yaradılıb: | 1993 |
| Tərəfindən: | Roberto Ierusalimschy, Luiz Henrique de Figueiredo və Waldemar Celes |
| İlham alıb: | C++,Modula,CLU,Scheme,Snobol |
| İlhamlanıb: | Io,GameMonkey,falcon,squirrel,MiniD |
| Lisenziyası: | MIT License |
| Veb səhifə: | http://www.lua.org/ |
LUA — Açıq qaynaq kodlu proqramlaşdırma dili. 1993-cü ildə Roberto Ierusalimschy, Luiz Henrique de Figueiredo və Waldemar Celes tərəfinədn yaradılmışdır. Geniş istifadə dairəsinə malikdir. Əsasən video oyunlar sahəsində məşhurdur(məs: World of Warcraft). Hal-hazırda Lua ilə Iphone üçün proqram yazmaq olur,məsələn Angry Birds. 2011-ci il iyun ayına TİOBE İndeksinə görə dünyanın 10 ən populyar proqramlaşdırma dilindən biridir.
Mündəricat
Proqlaşdırma dilində Nümunələr[redaktə | əsas redaktə]
Hello World[redaktə | əsas redaktə]
#!/usr/bin/lua
print("Hello World!")
Dəyişən elan etmək[redaktə | əsas redaktə]
#!/usr/bin/lua
a = "Hello World!"
print(a)
faktorial[redaktə | əsas redaktə]
function factorial(n)
local x = 1
for i = 2,n do
x = x * i
end
return x
end
Dövr operatorları[redaktə | əsas redaktə]
Luada 4 dövr operatoru var. While, Repeat, for, generik for.
While[redaktə | əsas redaktə]
local condition = true
while condition do
--Statements
end
Repeat[redaktə | əsas redaktə]
local condition = false
repeat
--Statements
until condition
until dən sonra verilmiş şərt(condition) true olana qədər dövr davam edir.
for[redaktə | əsas redaktə]
for index = 1,5 do
print(index)
end
dövr 5 dəfə icra olunur və hər dəfə 1-dən 5-ə qədər rəqəmlər ekrana verilir.
Generik for[redaktə | əsas redaktə]
for key,value in pairs(_G) do
print(key,value)
end
Funksiyalar[redaktə | əsas redaktə]
do
local oldprint = print -- Store current print function as oldprint
function print(s) -- Redefine print function, the usual print function can still be used
if s == "foo" then
oldprint("bar")
else
oldprint(s)
end
end
end
- C dilindən Lua funsiyasının çağrılması
#include <stdio.h>
#include <stdlib.h>
#include <lua.h>
#include <lauxlib.h>
int main()
{
lua_State *L = luaL_newstate();
if (luaL_dostring(L, "function foo (x,y) return x+y end")) exit(1);
lua_getglobal(L, "foo");
lua_pushinteger(L, 5);
lua_pushinteger(L, 3);
lua_call(L, 2, 1);
printf("Result: %d\n", lua_tointeger(L, -1));
lua_close(L);
return 0;
}
yuxarıdakı nümunənin nəticəsi
$ gcc -o example example.c -llua $ ./example Result: 8
Kitablar[redaktə | əsas redaktə]
- (2008) Lua Programming Gems. Lua.org. ISBN 978-85-903798-4-3.
- (2003) Game Programming with Python, Lua, and Ruby. Course Technology PTR. ISBN 1-59200-077-0.
- (2006) Programming in Lua, 2nd, Lua.org. ISBN 85-903798-2-5. (The 1st ed. is available online.)
- (2007) Beginning Lua Programming. Wrox Press. ISBN 0-470-06917-1.
- (2005) Game Development with Lua. Charles River Media. ISBN 1-58450-404-8.
- Takhteyev, Yuri (2012). Coding Places: Software Practice in a South American City. The MIT Press. ISBN 0262018071. Chapters 6 and 7 are dedicated to Lua, while others look at software in Brazil more broadly.
- Varma, Jayant (2012). Learn Lua for iOS Game Development. Apress. ISBN 1430246626.
Xarici keçidlər[redaktə | əsas redaktə]
|
||||||||||||||