카테고리 없음

Lua스크립트

och 2024. 11. 12. 20:44

Lua script정리

nginx와 함께 사용하면 좋은 퍼포먼스를 낼 수 있음.

HELLO LUA WORLD

print ("hello lua world")

a = 3

-- local variable Test
if true then
    local a = 20
    local b = "bbb"
    print(a)
    print(b)
end

print(a)
print(b) -- nil means null!

타입

--[[

    타입을 테스트 : number(숫자), nil(널값), string, boolean, table(배열)

]]--
local a = 10
print(type(a))

local a = nil
print(type(a))

local a = 42.42
print(type(a))

local a = 1 > 3
print(type(a))

a = {}
print(type(a))

a = {"lua", "tutorial"}
print(type(a))

연산자

--[[Operation TEST

1. 수식연산자 : + - * /(소수점까지 출력) % ^
2. 관계연산자 : == ~=(다르다) > < >= <=
3. 논리연산자 : and or not
4. 기타연산자 : ..(두 문자를 붙여줌) #(배열/테이블의 갯수 카운트)
]]--
print(1>3 and 1<3)
local a = {"hi", " my", " name", " is", " coh"}
print(a[1].."!!! "..a[2]..a[3]..a[4]..a[5])
print(#a)

반복문

-- 반복문 : while, for, repeat until
a = 10
while (a < 20)
do
    print("value of a:", a);
    a = a+1
end

for i = 10,20,1
do
    print(i)
end

a = 10
repeat
    print("value of a:", a)
    a = a+ 1
until( a > 15 )

조건문

if (조건) then A else B end

if (1>3 and 2>4)
then
    print("a and b is true")
else
    print("a and b is false")
end

함수

local function hihi(a,b)
    print("hello world")
    return 123
end

hihi() -- hello world
print(type(hihi)) -- function
print(hihi) -- function asd12..(함수 주소)
print(hihi()) -- hello world 123

Array