1.변수와 데이터 타입
-- 변수 선언과 데이터 할당
local name = "John"
local age = 30
local isStudent = true
2. 제어 구조
-- 조건문 (if-elseif-else)
if age < 18 then
print("You are underage.")
elseif age >= 18 and age < 65 then
print("You are an adult.")
else
print("You are a senior citizen.")
end
-- 반복문 (for)
for i = 1, 5 do
print("Count: " .. i)
end
3.함수
-- 함수 정의와 호출
function greet(name)
print("Hello, " .. name .. "!")
end
greet("Alice")
4.테이블
-- 테이블 생성과 접근
local person = {
name = "Bob",
age = 25,
isStudent = true
}
print(person.name) -- 출력: Bob
print(person.age) -- 출력: 25
5.라이브러리 함수
-- 문자열 처리 함수
local str = "Lua Programming"
print(string.upper(str)) -- 출력: LUA PROGRAMMING
-- 수학 함수
print(math.sqrt(25)) -- 출력: 5
6.클래스 및 객체 지향 프로그래밍:
-- 클래스 정의와 객체 생성
Person = {}
function Person:new(name)
local obj = {name = name}
setmetatable(obj, self)
self.__index = self
return obj
end
function Person:speak()
print("My name is " .. self.name)
end
local person1 = Person:new("Alice")
person1:speak() -- 출력: My name is Alice
7.코루틴
-- 코루틴 생성과 실행
co = coroutine.create(function ()
print("Coroutine is running")
end)
coroutine.resume(co) -- 출력: Coroutine is running
| 제목 | 작성자 | 작성일 | 조회 | |
|---|---|---|---|---|
| 공지 | 게시판 이용 안내+156 | 10-20 | 22473 | |
| 61818 | 19:26 | 1 | ||
| 61817 | 01-17 | 523 | ||
| 61816 | 메랜 h+1 | 01-15 | 826 | |
| 61815 | 01-15 | 766 | ||
| 61814 | 01-14 | 1030 | ||
| 61813 | 01-14 | 1236 | ||
| 61812 | 메랜 H메소+2 | 01-14 | 1124 | |
| 61811 | 01-12 | 1144 | ||
| 61810 | 01-12 | 1135 | ||
| 61809 | 01-11 | 1419 | ||
| 61808 | 01-10 | 1609 | ||
| 61807 | 01-10 | 1676 | ||
| 61806 | 01-09 | 1625 | ||
| 61805 | 01-08 | 1893 | ||
| 61804 | 01-07 | 1883 | ||
| 61803 | 01-07 | 2021 | ||
| 61802 | 01-06 | 2042 | ||
| 61801 | 01-06 | 1991 | ||
| 61800 | 01-05 | 2308 |
댓글1
뭐하시는분이쥐.. ?