1
0
mirror of https://github.com/adambard/learnxinyminutes-docs.git synced 2025-08-29 01:21:07 +02:00

change encoding of files

This commit is contained in:
wikibook
2013-08-13 15:47:49 +09:00
parent 04c0b273b0
commit cd104ee855
2 changed files with 363 additions and 363 deletions

View File

@@ -9,85 +9,85 @@ lang: ko-kr
---
```lua
-- <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20><> <20><>¥<EFBFBD><C2A5> <20>ּ<EFBFBD><D6BC><EFBFBD> <20>ǹ<EFBFBD><C7B9>մϴ<D5B4>.
-- 대시 두 개는 한 줄짜리 주석을 의미합니다.
--[[
[<EFBFBD><EFBFBD> ]<5D><> <20><> <20><><EFBFBD><EFBFBD> <20>߰<EFBFBD><DFB0>ϸ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20>ּ<EFBFBD><D6BC><EFBFBD> <20>˴ϴ<CBB4>.
[와 ]를 두 개씩 추가하면 여러 줄 주석이 됩니다.
--]]
----------------------------------------------------
-- 1. <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><20><><EFBFBD><EFBFBD>
-- 1. 변수와 흐름 제어
----------------------------------------------------
num = 42 -- <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>ڴ<EFBFBD> double<EFBFBD>Դϴ<EFBFBD>.
-- <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ʿ<EFBFBD><CABF><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>. 64<EFBFBD><EFBFBD>Ʈ double<EFBFBD><EFBFBD>
-- <EFBFBD><EFBFBD>Ȯ<EFBFBD><EFBFBD> int <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϱ<EFBFBD> <20><><EFBFBD><EFBFBD> 52<35><32>Ʈ<EFBFBD><C6AE> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
-- <EFBFBD>ֽ<EFBFBD><EFBFBD>ϴ<EFBFBD>. 52<35><32>Ʈ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> int <20><><EFBFBD><EFBFBD> <20><><EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD>
-- <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>е<EFBFBD><D0B5><EFBFBD> <20><><EFBFBD>õ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ʽ<EFBFBD><CABD>ϴ<EFBFBD>.
num = 42 -- 모든 숫자는 double입니다.
-- 놀랄 필요는 없습니다. 64비트 double
-- 정확한 int 값을 저장하기 위해 52비트로 구성돼
-- 있습니다. 52비트 이하의 int 값에 대해서는
-- 장비 정밀도와 관련된 문제가 생기지 않습니다.
s = 'walternate' -- <EFBFBD><EFBFBD><EFBFBD>̽<EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>Һ<EFBFBD> <20><><EFBFBD>ڿ<EFBFBD>
t = "ū<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǥ<EFBFBD><EFBFBD> <20><20>˴ϴ<CBB4>"
u = [[ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>ȣ<EFBFBD><C8A3>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD>
<EFBFBD><EFBFBD>Ÿ<EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>.]]
t = nil -- <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> t. <20><><EFBFBD>ƴ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>÷<EFBFBD><C3B7><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>մϴ<D5B4>.
s = 'walternate' -- 파이썬과 같은 불변 문자열
t = "큰따옴표를 써도 됩니다"
u = [[ 이중 대괄호는
여러 줄 문자열을
나타냅니다.]]
t = nil -- 미정의 t. 루아는 가비지 컬렉션을 지원합니다.
-- <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> do/end<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> Ű<><C5B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>Ÿ<EFBFBD><C5B8><EFBFBD>ϴ<EFBFBD>:
-- 블록은 do/end와 같은 키워드로 나타냅니다:
while num < 50 do
num = num + 1 -- ++<EFBFBD><EFBFBD> += <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD> <20><> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>.
num = num + 1 -- ++ += 유형의 연산자는 쓸 수 없습니다.
end
-- If <EFBFBD><EFBFBD>:
-- If :
if num > 40 then
print('40 <EFBFBD>̻<EFBFBD>')
elseif s ~= 'walternate' then -- ~=<EFBFBD><EFBFBD> '<27><><EFBFBD><EFBFBD> <20>ʴ<EFBFBD>'<27>Դϴ<D4B4>.
-- <EFBFBD><EFBFBD><EFBFBD>ϼ<EFBFBD> <20>˻<EFBFBD><CBBB><EFBFBD> <20><><EFBFBD>̽<EFBFBD><CCBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ==<3D>Դϴ<D4B4>.
-- <EFBFBD><EFBFBD><EFBFBD>ڿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><> <20>ֽ<EFBFBD><D6BD>ϴ<EFBFBD>.
io.write('not over 40\n') -- <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> stdout<75><74> <20><><EFBFBD>ϴ<EFBFBD>.
print('40 이상')
elseif s ~= 'walternate' then -- ~=은 '같지 않다'입니다.
-- 동일성 검사는 파이썬과 마찬가지로 ==입니다.
-- 문자열에도 쓸 수 있습니다.
io.write('not over 40\n') -- 기본적으로 stdout에 씁니다.
else
-- <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><EFBFBD><E2BABB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Դϴ<D4B4>.
thisIsGlobal = 5 -- <EFBFBD><EFBFBD>Ÿ ǥ<><C7A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>Ϲ<EFBFBD><CFB9><EFBFBD><EFBFBD>Դϴ<D4B4>.
-- 변수는 기본적으로 전역 변수입니다.
thisIsGlobal = 5 -- 낙타 표기법이 일반적입니다.
-- <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>:
local line = io.read() -- <EFBFBD><EFBFBD><EFBFBD><EFBFBD> stdin <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>н<EFBFBD><D0BD>ϴ<EFBFBD>
-- 변수를 지역 변수로 만드는 방법은 다음과 같습니다:
local line = io.read() -- 다음 stdin 줄을 읽습니다
-- <EFBFBD><EFBFBD><EFBFBD>ڿ<EFBFBD> <20><><EFBFBD><EFBFBD><E1BFA1> .. <20><><EFBFBD><EFBFBD><EFBFBD>ڸ<EFBFBD> <20><><EFBFBD>ϴ<EFBFBD>:
print('<EFBFBD>ܿ<EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ֽ<EFBFBD><D6BD>ϴ<EFBFBD>, ' .. line)
-- 문자열 연결에는 .. 연산자를 씁니다:
print('겨울이 오고 있습니다, ' .. line)
end
-- <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> nil<69><6C> <20><>ȯ<EFBFBD>մϴ<D5B4>.
-- <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ڵ带 <20><><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ʽ<EFBFBD><CABD>ϴ<EFBFBD>:
foo = anUnknownVariable -- <EFBFBD><EFBFBD><EFBFBD><EFBFBD> foo<EFBFBD><EFBFBD> nil<EFBFBD>Դϴ<EFBFBD>.
-- 미정의 변수는 nil을 반환합니다.
-- 다음 코드를 실행해도 오류가 나지 않습니다:
foo = anUnknownVariable -- 이제 foo nil입니다.
aBoolValue = false
-- nil<EFBFBD><EFBFBD> false<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դϴ<D4B4>; 0<EFBFBD><EFBFBD> ''<EFBFBD><EFBFBD> <20><><EFBFBD>Դϴ<D4B4>!
-- nil false만이 거짓값입니다; 0 ''은 참입니다!
if not aBoolValue then print('twas false') end
-- 'or'<EFBFBD><EFBFBD> 'and'<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>(short-circuit)<EFBFBD>˴ϴ<EFBFBD>.
-- <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ڵ<EFBFBD><DAB5><EFBFBD> C/<2F>ڹٽ<DAB9>ũ<EFBFBD><C5A9>Ʈ<EFBFBD><C6AE> a?b:c <20><><EFBFBD><EFBFBD><EFBFBD>ڿ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>մϴ<D5B4>:
-- 'or' 'and'는 단축 평가(short-circuit)됩니다.
-- 다음 코드는 C/자바스크립트의 a?b:c 연산자와 비슷합니다:
ans = aBoolValue and 'yes' or 'no' --> 'no'
karlSum = 0
for i = 1, 100 do -- <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>ҵ<EFBFBD> <20><><EFBFBD>Ե˴ϴ<CBB4>.
for i = 1, 100 do -- 범위에는 마지막 요소도 포함됩니다.
karlSum = karlSum + i
end
-- ī<EFBFBD><EFBFBD>Ʈ <20>ٿ<EFBFBD><D9BF><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> "100, 1, -1"<22><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>ϴ<EFBFBD>.
-- 카운트 다운을 할 때는 "100, 1, -1"을 범위로 씁니다.
fredSum = 0
for j = 100, 1, -1 do fredSum = fredSum + j end
-- <EFBFBD>Ϲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> begin, end[, step]<EFBFBD>Դϴ<EFBFBD>.
-- 일반적으로 범위는 begin, end[, step]입니다.
-- <EFBFBD><EFBFBD> <20>ٸ<EFBFBD> <20>ݺ<EFBFBD><DDBA><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>:
-- 또 다른 반복문 구문은 다음과 같습니다:
repeat
print('<EFBFBD>̷<EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>')
print('미래의 방식')
num = num - 1
until num == 0
----------------------------------------------------
-- 2. <EFBFBD>Լ<EFBFBD>
-- 2. 함수
----------------------------------------------------
function fib(n)
@@ -95,10 +95,10 @@ function fib(n)
return fib(n - 2) + fib(n - 1)
end
-- Ŭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>͸<EFBFBD> <20>Լ<EFBFBD><D4BC><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20>ֽ<EFBFBD><D6BD>ϴ<EFBFBD>:
-- 클로저와 익명 함수도 사용할 수 있습니다:
function adder(x)
-- <EFBFBD><EFBFBD>ȯ<EFBFBD><EFBFBD> <20>Լ<EFBFBD><D4BC><EFBFBD> adder<65><72> ȣ<><C8A3><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD> x<><78>
-- <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>˴ϴ<CBB4>:
-- 반환된 함수는 adder가 호출될 때 생성되고 x의
-- 값이 유지됩니다:
return function (y) return x + y end
end
a1 = adder(9)
@@ -106,104 +106,104 @@ a2 = adder(36)
print(a1(16)) --> 25
print(a2(64)) --> 100
-- <EFBFBD><EFBFBD>ȯ<EFBFBD><EFBFBD>, <20>Լ<EFBFBD> ȣ<><C8A3>, <20>Ҵ繮<D2B4><E7B9AE> <20><><EFBFBD>̰<EFBFBD> <20>ٸ<EFBFBD>
-- <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>Ʈ<EFBFBD><C6AE> <20><><EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>մϴ<D5B4>.
-- <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʈ<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> nil<69><6C> <20>Ҵ<EFBFBD>/<2F><>ȯ<EFBFBD>ǰ<EFBFBD>
-- <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʈ<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>.
-- 반환문, 함수 호출, 할당문은 길이가 다른
-- 값의 리스트에 대해서도 모두 동작합니다.
-- 리스트에 값이 더 적을 때는 nil이 할당/반환되고
-- 리스트에 값이 더 많을 때는 나머지 값은 버려집니다.
x, y, z = 1, 2, 3, 4
-- <EFBFBD><EFBFBD><EFBFBD><EFBFBD> x = 1, y = 2, z = 3<EFBFBD>̰<EFBFBD> 4<><34> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>.
-- 이제 x = 1, y = 2, z = 3이고 4는 버려집니다.
function bar(a, b, c)
print(a, b, c)
return 4, 8, 15, 16, 23, 42
end
x, y = bar('zaphod') --> "zaphod nil nil"<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
-- <EFBFBD><EFBFBD><EFBFBD><EFBFBD> x = 4, y = 8<EFBFBD>̰<EFBFBD> 15~42<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>.
x, y = bar('zaphod') --> "zaphod nil nil"가 출력
-- 이제 x = 4, y = 8이고 15~42의 값은 버려집니다.
-- <EFBFBD>Լ<EFBFBD><EFBFBD><EFBFBD> <20>ϱ<EFBFBD> <20><>ü<EFBFBD>̰<EFBFBD>, <20><><EFBFBD><EFBFBD>/<2F><><EFBFBD><EFBFBD> <20><>ȿ<EFBFBD><C8BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
-- <EFBFBD><EFBFBD> <20>ֽ<EFBFBD><D6BD>ϴ<EFBFBD>. <20>Ʒ<EFBFBD><C6B7><EFBFBD> <20><> <20>Լ<EFBFBD><D4BC><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>:
-- 함수는 일급 객체이고, 지역/전역 유효범위를 가질
-- 수 있습니다. 아래의 두 함수는 같습니다:
function f(x) return x * x end
f = function (x) return x * x end
-- <EFBFBD>׸<EFBFBD><EFBFBD><EFBFBD> <20>Ʒ<EFBFBD><C6B7><EFBFBD> <20><> <20>Լ<EFBFBD><D4BC><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դϴ<D4B4>:
-- 그리고 아래의 두 함수도 마찬가지입니다:
local function g(x) return math.sin(x) end
local g; g = function (x) return math.sin(x) end
-- 'local g'<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD> g<><67> <20><><EFBFBD><EFBFBD> <20>Լ<EFBFBD><D4BC><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>.
-- 'local g'라고 선언하면 g를 지역 함수로 만듭니다.
-- <EFBFBD>׳<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><20>Լ<EFBFBD><D4BC><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>մϴ<D5B4>.
-- 그나저나 삼각 함수는 라디안 단위로 동작합니다.
-- <EFBFBD>Լ<EFBFBD><EFBFBD><EFBFBD> ȣ<><C8A3><EFBFBD><EFBFBD> <20><> <20><><EFBFBD>ڿ<EFBFBD> <20>Ű<EFBFBD><C5B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ϳ<EFBFBD><CFB3><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ѵٸ<D1B4>
-- <EFBFBD><EFBFBD>ȣ<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ʾƵ<CABE> <20>˴ϴ<CBB4>:
print 'hello' -- <EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>մϴ<D5B4>.
-- 함수를 호출할 때 문자열 매개변수를 하나만 전달한다면
-- 괄호를 쓰지 않아도 됩니다:
print 'hello' -- 잘 동작합니다.
----------------------------------------------------
-- 3. <EFBFBD><EFBFBD><EFBFBD>̺<EFBFBD>
-- 3. 테이블
----------------------------------------------------
-- <EFBFBD><EFBFBD><EFBFBD>̺<EFBFBD> = <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ڷᱸ<DAB7><E1B1B8><EFBFBD>μ<EFBFBD>, <20><><EFBFBD><EFBFBD> <20><EFBFBD>Դϴ<D4B4>.
-- PHP<EFBFBD><EFBFBD> <20><EFBFBD>̳<EFBFBD> <20>ڹٽ<DAB9>ũ<EFBFBD><C5A9>Ʈ<EFBFBD><C6AE> <20><>ü<EFBFBD><C3BC> <20><><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD>,
-- <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʈ<EFBFBD>ε<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20>ִ<EFBFBD> <20>ؽ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>ųʸ<C5B3><CAB8>Դϴ<D4B4>.
-- 테이블 = 루아의 유일한 복합 자료구조로서, 연관 배열입니다.
-- PHP의 배열이나 자바스크립트의 객체와 비슷하며,
-- 리스트로도 사용할 수 있는 해시 기반의 딕셔너리입니다.
-- <EFBFBD><EFBFBD><EFBFBD>̺<EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>ųʸ<C5B3>/<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϱ<EFBFBD>:
-- 테이블을 딕셔너리/맵으로 사용하기:
-- <EFBFBD><EFBFBD><EFBFBD>ųʸ<EFBFBD> <20><><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD> <20><EFBFBD><E2BABB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>ڿ<EFBFBD> Ű<><C5B0> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>:
-- 딕셔너리 리터럴은 기본적으로 문자열 키를 가집니다:
t = {key1 = 'value1', key2 = false}
-- <EFBFBD><EFBFBD><EFBFBD>ڿ<EFBFBD> Ű<><C5B0><EFBFBD><EFBFBD> <20>ڹٽ<DAB9>ũ<EFBFBD><C5A9>Ʈ<EFBFBD><C6AE> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> ǥ<><C7A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><> <20>ֽ<EFBFBD><D6BD>ϴ<EFBFBD>:
print(t.key1) -- 'value1'<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>.
t.newKey = {} -- <EFBFBD><EFBFBD> Ű/<2F><> <20><><EFBFBD><EFBFBD> <20>߰<EFBFBD>.
t.key2 = nil -- <EFBFBD><EFBFBD><EFBFBD>̺<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> key2<79><32> <20><><EFBFBD><EFBFBD>.
-- 문자열 키에는 자바스크립트와 유사한 점 표기법을 쓸 수 있습니다:
print(t.key1) -- 'value1'을 출력.
t.newKey = {} -- 새 키/값 쌍을 추가.
t.key2 = nil -- 테이블에서 key2를 제거.
-- (nil<EFBFBD><EFBFBD> <20>ƴ<EFBFBD>) <20><><EFBFBD><EFBFBD> Ű<><C5B0> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD> <20><><EFBFBD>ͷ<EFBFBD> ǥ<><C7A5><EFBFBD><EFBFBD>:
-- (nil이 아닌) 값을 키로 사용하는 리터럴 표기법:
u = {['@!#'] = 'qbert', [{}] = 1729, [6.28] = 'tau'}
print(u[6.28]) -- "tau"<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
print(u[6.28]) -- "tau"가 출력
-- Ű <20><>Ī<EFBFBD><C4AA> <20><EFBFBD><E2BABB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>ڿ<EFBFBD> <20><><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD> <20><><EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
-- <EFBFBD><EFBFBD><EFBFBD>̺<EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD> <20>ĺ<EFBFBD><C4BA>ڷ<EFBFBD> <20>մϴ<D5B4>.
-- 키 매칭은 기본적으로 숫자와 문자열에 대해서는 값으로 하지만
-- 테이블에 대해서는 식별자로 합니다.
a = u['@!#'] -- Now a = 'qbert'.
b = u[{}] -- We might expect 1729, but it's nil:
a = u['@!#'] -- <EFBFBD><EFBFBD><EFBFBD><EFBFBD> a<><61> 'qbert'<EFBFBD>Դϴ<EFBFBD>.
b = u[{}] -- 1729<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>߰<EFBFBD><DFB0><EFBFBD><EFBFBD><EFBFBD> nil<69>Դϴ<D4B4>:
-- Ž<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϱ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> b<><62> nil<69>Դϴ<D4B4>. Ž<><C5BD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
-- <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Ű<><C5B0> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Ű<><C5B0> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>ü<EFBFBD><C3BC> <20>ƴϱ<C6B4>
-- <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դϴ<EFBFBD>. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>ڿ<EFBFBD> <20><> <20><><EFBFBD>ڰ<EFBFBD> <20><> <20><> <20>̽ļ<CCBD> <20>ִ<EFBFBD> Ű<>Դϴ<D4B4>.
a = u['@!#'] -- 이제 a는 'qbert'입니다.
b = u[{}] -- 1729를 예상했겠지만 nil입니다:
-- 탐색이 실패하기 때문에 b는 nil입니다. 탐색이 실패하는 이유는
-- 사용된 키가 원본 값을 저장할 때 사용한 키와 동일한 객체가 아니기
-- 때문입니다. 따라서 문자열 및 숫자가 좀 더 이식성 있는 키입니다.
-- <EFBFBD><EFBFBD><EFBFBD>̺<EFBFBD> <20>ϳ<EFBFBD><CFB3><EFBFBD> <20>Ű<EFBFBD><C5B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>ϴ<EFBFBD> <20>Լ<EFBFBD><D4BC><EFBFBD> ȣ<><C8A3><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><>ȣ<EFBFBD><C8A3> <20>ʿ<EFBFBD><CABF><EFBFBD><EFBFBD><EFBFBD> <20>ʽ<EFBFBD><CABD>ϴ<EFBFBD>:
-- 테이블 하나를 매개변수로 취하는 함수를 호출할 때는 괄호가 필요하지 않습니다:
function h(x) print(x.key1) end
h{key1 = 'Sonmi~451'} -- 'Sonmi~451'<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>.
h{key1 = 'Sonmi~451'} -- 'Sonmi~451'를 출력.
for key, val in pairs(u) do -- <EFBFBD><EFBFBD><EFBFBD>̺<EFBFBD> <20><>ȸ
for key, val in pairs(u) do -- 테이블 순회
print(key, val)
end
-- _G<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> Ư<><C6AF><EFBFBD><EFBFBD> <20><><EFBFBD>̺<EFBFBD><CCBA>Դϴ<D4B4>.
print(_G['_G'] == _G) -- 'true'<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
-- _G는 모든 전역 멤버에 대한 특별한 테이블입니다.
print(_G['_G'] == _G) -- 'true'가 출력
-- <EFBFBD><EFBFBD><EFBFBD>̺<EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>Ʈ/<2F><EFBFBD><E8BFAD> <20><><EFBFBD><EFBFBD><EFBFBD>ϱ<EFBFBD>:
-- 테이블을 리스트/배열로 사용하기:
-- <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʈ <20><><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD> <20>Ϲ<EFBFBD><CFB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> int Ű<><C5B0> <20><><EFBFBD><EFBFBD><EFBFBD>˴ϴ<CBB4>:
-- 리스트 리터럴은 암묵적으로 int 키로 설정됩니다:
v = {'value1', 'value2', 1.21, 'gigawatts'}
for i = 1, #v do -- #v<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>Ʈ v<><76> ũ<><C5A9><EFBFBD>Դϴ<D4B4>.
print(v[i]) -- <EFBFBD>ε<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1<><31><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>մϴ<D5B4>!! <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ƴմϴ<D5B4>!
for i = 1, #v do -- #v는 리스트 v의 크기입니다.
print(v[i]) -- 인덱스가 1에서 시작합니다!! 제정신이 아닙니다!
end
-- 'list'<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> Ÿ<><C5B8><EFBFBD><EFBFBD> <20>ƴմϴ<D5B4>. v<><76> <20><><EFBFBD>ӵ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Ű<><C5B0> <20><><EFBFBD>Ե<EFBFBD>
-- <EFBFBD><EFBFBD><EFBFBD>̺<EFBFBD><EFBFBD>̰<EFBFBD> <20><><EFBFBD><EFBFBD>Ʈ<EFBFBD><C6AE> <20><><EFBFBD>޵<EFBFBD> <20><><EFBFBD>Դϴ<D4B4>.
-- 'list'는 실제 타입이 아닙니다. v는 연속된 정수형 키가 포함된
-- 테이블이고 리스트로 취급될 뿐입니다.
----------------------------------------------------
-- 3.1 <EFBFBD><EFBFBD>Ÿ<EFBFBD><EFBFBD><EFBFBD>̺<EFBFBD><EFBFBD><EFBFBD> <20><>Ÿ<EFBFBD>޼<EFBFBD><DEBC><EFBFBD>
-- 3.1 메타테이블과 메타메서드
----------------------------------------------------
-- <EFBFBD><EFBFBD><EFBFBD>̺<EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>̺<EFBFBD><CCBA><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ε<EFBFBD><CEB5><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϰ<EFBFBD> <20>ϴ<EFBFBD> <20><>Ÿ<EFBFBD><C5B8><EFBFBD>̺<EFBFBD><CCBA><EFBFBD>
-- <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20>ֽ<EFBFBD><D6BD>ϴ<EFBFBD>. <20><><EFBFBD>߿<EFBFBD> <20><>Ÿ<EFBFBD><C5B8><EFBFBD>̺<EFBFBD><CCBA><EFBFBD> <20><EFBFBD><EEB6BB> <20>ڹٽ<DAB9>ũ<EFBFBD><C5A9>Ʈ
-- <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ÿ<EFBFBD>԰<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><CFB4><EFBFBD> <20><><EFBFBD><EFBFBD>ڽ<EFBFBD><DABD>ϴ<EFBFBD>.
-- 테이블은 테이블에 연산자 오버로딩을 가능하게 하는 메타테이블을
-- 가질 수 있습니다. 나중에 메타테이블이 어떻게 자바스크립트
-- 프로토타입과 같은 행위를 지원하는지 살펴보겠습니다.
f1 = {a = 1, b = 2} -- <EFBFBD>м<EFBFBD> a/b<EFBFBD><EFBFBD> ǥ<><C7A5>
f1 = {a = 1, b = 2} -- 분수 a/b를 표현
f2 = {a = 2, b = 3}
-- <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ڵ<EFBFBD><DAB5><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>մϴ<D5B4>:
-- 다음 코드는 실패합니다:
-- s = f1 + f2
metafraction = {}
@@ -217,30 +217,30 @@ end
setmetatable(f1, metafraction)
setmetatable(f2, metafraction)
s = f1 + f2 -- f1<EFBFBD><EFBFBD> <20><>Ÿ<EFBFBD><C5B8><EFBFBD>̺<EFBFBD><CCBA><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> __add(f1, f2)<EFBFBD><EFBFBD> ȣ<><C8A3>
s = f1 + f2 -- f1의 메타테이블을 대상으로 __add(f1, f2)를 호출
-- f1<EFBFBD><EFBFBD> f2<EFBFBD><EFBFBD> <20>ڹٽ<DAB9>ũ<EFBFBD><C5A9>Ʈ<EFBFBD><C6AE> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ÿ<EFBFBD>԰<EFBFBD> <20>޸<EFBFBD> <20><> <20><>Ÿ<EFBFBD><C5B8><EFBFBD>̺<EFBFBD><CCBA><EFBFBD> <20><><EFBFBD><EFBFBD>
-- Ű<EFBFBD><EFBFBD> <20><><EFBFBD> getmetatable(f1)<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>޾ƿ;<C6BF> <20>մϴ<D5B4>.
-- <EFBFBD><EFBFBD>Ÿ<EFBFBD><EFBFBD><EFBFBD>̺<EFBFBD><EFBFBD><EFBFBD> __add <20><><EFBFBD><EFBFBD> <20><><EFBFBD>ư<EFBFBD> <20>˰<EFBFBD> <20>ִ<EFBFBD> Ű<><C5B0> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>Ϲ<EFBFBD> <20><><EFBFBD>̺<EFBFBD><CCBA>Դϴ<D4B4>.
-- f1 f2는 자바스크립트의 프로토타입과 달리 각 메타테이블에 대한
-- 키가 없어서 getmetatable(f1)과 같이 받아와야 합니다.
-- 메타테이블은 __add 같은 루아가 알고 있는 키가 지정된 일반 테이블입니다.
-- <EFBFBD>׷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> s<><73> <20><>Ÿ<EFBFBD><C5B8><EFBFBD>̺<EFBFBD><CCBA><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ʱ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>մϴ<D5B4>.
-- 그렇지만 다음 줄은 s가 메타테이블을 가지고 있지 않기 때문에 실패합니다.
-- t = s + s
-- <EFBFBD>Ʒ<EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> Ŭ<><C5AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>̷<EFBFBD><CCB7><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>߻<EFBFBD><DFBB><EFBFBD><EFBFBD><EFBFBD> <20>ʽ<EFBFBD><CABD>ϴ<EFBFBD>.
-- 아래와 같이 클래스와 유사한 패턴은 이러한 문제가 발생하지 않습니다.
-- <EFBFBD><EFBFBD>Ÿ<EFBFBD><EFBFBD><EFBFBD>̺<EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> __index<65><78> <20><><EFBFBD><EFBFBD> <20>̿<EFBFBD><CCBF><EFBFBD> Ž<><C5BD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ε<EFBFBD><CEB5>մϴ<D5B4>:
-- 메타테이블에 대한 __index는 점을 이용한 탐색을 오버로드합니다:
defaultFavs = {animal = 'gru', food = 'donuts'}
myFavs = {food = 'pizza'}
setmetatable(myFavs, {__index = defaultFavs})
eatenBy = myFavs.animal -- <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>մϴ<EFBFBD>! <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><>Ÿ<EFBFBD><C5B8><EFBFBD>̺<EFBFBD>!
eatenBy = myFavs.animal -- 동작합니다! 고마워요, 메타테이블!
-- <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>Ÿ<EFBFBD><C5B8><EFBFBD>̺<EFBFBD> Ž<><C5BD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><>Ÿ<EFBFBD><C5B8><EFBFBD>̺<EFBFBD><CCBA><EFBFBD> __index <20><><EFBFBD><EFBFBD> <20>̿<EFBFBD><CCBF><EFBFBD>
-- <EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><EFBFBD>ϰ<EFBFBD>, <20>̷<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ݺ<EFBFBD><DDBA>˴ϴ<CBB4>.
-- 직접적인 메타테이블 탐색이 실패할 경우 메타테이블의 __index 값을 이용해
-- 재시도하고, 이런 과정이 반복됩니다.
-- __index <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><> <20><><EFBFBD><EFBFBD>ȭ<EFBFBD><C8AD> Ž<><C5BD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> function(tbl, key)<EFBFBD><EFBFBD>
-- <EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ֽ<EFBFBD><D6BD>ϴ<EFBFBD>.
-- __index 값은 좀 더 세분화된 탐색을 위해 function(tbl, key)
-- 될 수도 있습니다.
-- __index, __add, ...<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><>Ÿ<EFBFBD>޼<EFBFBD><DEBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>մϴ<D5B4>.
-- <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>Ÿ<EFBFBD>޼<EFBFBD><DEBC><20><><EFBFBD><EFBFBD> <20><><EFBFBD>̺<EFBFBD><CCBA><EFBFBD> <20><>ü <20><><EFBFBD><EFBFBD><EFBFBD>Դϴ<D4B4>.
-- __index, __add, ...의 값을 메타메서드라고 합니다.
-- 다음은 메타메서드를 가진 테이블의 전체 목록입니다.
-- __add(a, b) for a + b
-- __sub(a, b) for a - b
@@ -254,18 +254,18 @@ eatenBy = myFavs.animal --
-- __eq(a, b) for a == b
-- __lt(a, b) for a < b
-- __le(a, b) for a <= b
-- __index(a, b) <fn<EFBFBD>̳<EFBFBD> <20><><EFBFBD>̺<EFBFBD>> for a.b
-- __index(a, b) <fn이나 테이블> for a.b
-- __newindex(a, b, c) for a.b = c
-- __call(a, ...) for a(...)
----------------------------------------------------
-- 3.2 Ŭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>̺<EFBFBD><CCBA><EFBFBD> <20><><EFBFBD><EFBFBD>
-- 3.2 클래스 형태의 테이블과 상속
----------------------------------------------------
-- <EFBFBD><EFBFBD><EFBFBD>ƿ<EFBFBD><EFBFBD><EFBFBD> Ŭ<><C5AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD>̺<EFBFBD><CCBA><EFBFBD> <20><>Ÿ<EFBFBD><C5B8><EFBFBD>̺<EFBFBD><CCBA><EFBFBD>
-- <EFBFBD>̿<EFBFBD><EFBFBD><EFBFBD> Ŭ<><C5AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>پ<EFBFBD><D9BE><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ֽ<EFBFBD><D6BD>ϴ<EFBFBD>.
-- 루아에는 클래스가 내장돼 있지 않으며, 테이블과 메타테이블을
-- 이용해 클래스를 만드는 다양한 방법이 있습니다.
-- <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ϴ<EFBFBD><CFB4><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>մϴ<D5B4>.
-- 다음 예제에 대한 설명은 하단을 참조합니다.
Dog = {} -- 1.
@@ -282,25 +282,25 @@ end
mrDog = Dog:new() -- 7.
mrDog:makeSound() -- 'I say woof' -- 8.
-- 1. Dog<EFBFBD><EFBFBD> Ŭ<><C5AC><EFBFBD><EFBFBD>ó<EFBFBD><C3B3> <20><><EFBFBD><EFBFBD><EFBFBD>մϴ<D5B4>. <20><><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD> <20><><EFBFBD>̺<EFBFBD><CCBA>Դϴ<D4B4>.
-- 2. function <EFBFBD><EFBFBD><EFBFBD>̺<EFBFBD><EFBFBD><EFBFBD>:fn(...)<EFBFBD><EFBFBD>
-- function <EFBFBD><EFBFBD><EFBFBD>̺<EFBFBD><EFBFBD><EFBFBD>.fn(self, ...)<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>.
-- :<EFBFBD><EFBFBD> self<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ù <20><>° <20><><EFBFBD>ڸ<EFBFBD> <20>߰<EFBFBD><DFB0><EFBFBD> <20><><EFBFBD>Դϴ<D4B4>.
-- self<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><EFBFBD><EEB6BB> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ñ<EFBFBD><C3B1>ϴٸ<CFB4> <20>Ʒ<EFBFBD><C6B7><EFBFBD> 7<><37> 8<><38> <20>о<D0BE><EEBAB8><EFBFBD><EFBFBD>.
-- 3. newObj<EFBFBD><EFBFBD> Dog Ŭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ν<EFBFBD><CEBD>Ͻ<EFBFBD><CFBD><EFBFBD> <20>˴ϴ<CBB4>.
-- 4. self = <EFBFBD>ν<EFBFBD><EFBFBD>Ͻ<EFBFBD>ȭ<EFBFBD>Ǵ<EFBFBD> Ŭ<><C5AC><EFBFBD><EFBFBD>.
-- <EFBFBD>ַ<EFBFBD> self = Dog<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>̿<EFBFBD><CCBF>ϸ<EFBFBD> <20>̰<EFBFBD><CCB0><EFBFBD> <20>ٲ<EFBFBD> <20><> <20>ֽ<EFBFBD><D6BD>ϴ<EFBFBD>.
-- newObj<EFBFBD><EFBFBD> <20><>Ÿ<EFBFBD><C5B8><EFBFBD>̺<EFBFBD><CCBA><EFBFBD> self<EFBFBD><EFBFBD> __index<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> self<6C><66> <20><><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD>
-- newObj<EFBFBD><EFBFBD> self<EFBFBD><EFBFBD> <20>Լ<EFBFBD><D4BC><EFBFBD> <20><><EFBFBD><EFBFBD> <20>˴ϴ<CBB4>.
-- 5. <EFBFBD><EFBFBD><EFBFBD><EFBFBD>: setmetatable<EFBFBD><EFBFBD> ù <20><>° <20><><EFBFBD>ڸ<EFBFBD> <20><>ȯ<EFBFBD>մϴ<D5B4>.
-- 6. :<EFBFBD><EFBFBD> 2<><32><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>Ͱ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>̹<EFBFBD><CCB9><EFBFBD><EFBFBD><EFBFBD> self<EFBFBD><EFBFBD>
-- Ŭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ƴ<EFBFBD> <20>ν<EFBFBD><CEBD>Ͻ<EFBFBD><CFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20>ֽ<EFBFBD><D6BD>ϴ<EFBFBD>.
-- 7. Dog.new(Dog)<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD> new()<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> self = Dog<EFBFBD>Դϴ<EFBFBD>.
-- 8. mrDog.makeSound(mrDog)<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD> self = mrDog<EFBFBD>Դϴ<EFBFBD>.
-- 1. Dog는 클래스처럼 동작합니다. 실제로는 테이블입니다.
-- 2. function 테이블명:fn(...)
-- function 테이블명.fn(self, ...)과 같습니다.
-- : self라는 첫 번째 인자를 추가할 뿐입니다.
-- self가 값을 어떻게 얻는지 궁금하다면 아래의 7과 8을 읽어보세요.
-- 3. newObj Dog 클래스의 인스턴스가 됩니다.
-- 4. self = 인스턴스화되는 클래스.
-- 주로 self = Dog이지만 상속을 이용하면 이것을 바꿀 수 있습니다.
-- newObj의 메타테이블과 self __index를 모두 self에 설정하면
-- newObj self의 함수를 갖게 됩니다.
-- 5. 참고: setmetatable은 첫 번째 인자를 반환합니다.
-- 6. :는 2에서 설명한 것과 같이 동작하지만 이번에는 self
-- 클래스가 아닌 인스턴스라고 예상할 수 있습니다.
-- 7. Dog.new(Dog)과 같으므로 new()에서는 self = Dog입니다.
-- 8. mrDog.makeSound(mrDog)과 같으므로 self = mrDog입니다.
----------------------------------------------------
-- <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>:
-- 상속 예제:
LoudDog = Dog:new() -- 1.
@@ -312,19 +312,19 @@ end
seymour = LoudDog:new() -- 3.
seymour:makeSound() -- 'woof woof woof' -- 4.
-- 1. LoudDog<EFBFBD><EFBFBD> Dog<EFBFBD><EFBFBD> <20>޼<EFBFBD><DEBC><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>˴ϴ<CBB4>.
-- 2. self<EFBFBD><EFBFBD> new()<EFBFBD><EFBFBD><EFBFBD><EFBFBD> 'sound' Ű<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>. 3<><33> <20><><EFBFBD><EFBFBD><EFBFBD>ϼ<EFBFBD><CFBC><EFBFBD>.
-- 3. LoudDog.new(LoudDog)<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>, LoudDog<EFBFBD><EFBFBD> 'new' Ű<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
-- <EFBFBD><EFBFBD>Ÿ<EFBFBD><EFBFBD><EFBFBD>̺<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> __index = Dog<EFBFBD>̱<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Dog.new(LoudDog)<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
-- <EFBFBD><EFBFBD>ȯ<EFBFBD>˴ϴ<EFBFBD>.
-- <EFBFBD><EFBFBD><EFBFBD><EFBFBD>: seymour<EFBFBD><EFBFBD> <20><>Ÿ<EFBFBD><C5B8><EFBFBD>̺<EFBFBD><CCBA><EFBFBD> LoudDog<EFBFBD>̰<EFBFBD> LoudDog.__index<EFBFBD><EFBFBD>
-- LoudDog<EFBFBD>Դϴ<EFBFBD>. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> seymour.key<EFBFBD><EFBFBD> seymour.key,
-- LoudDog.key, Dog.key<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD≯<EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Ű<><C5B0> <20><20><><EFBFBD>̺<EFBFBD><CCBA><EFBFBD>
-- <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>Դϴ<D4B4>.
-- 4. 'makeSound' Ű<EFBFBD><EFBFBD> LoudDog<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>߰<EFBFBD><DFB0><EFBFBD> <20><> <20>ֽ<EFBFBD><D6BD>ϴ<EFBFBD>.
-- <EFBFBD>̰<EFBFBD><EFBFBD><EFBFBD> LoudDog.makeSound(seymour)<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>.
-- 1. LoudDog Dog의 메서드와 변수를 갖게 됩니다.
-- 2. self new()에서 'sound' 키를 가집니다. 3을 참고하세요.
-- 3. LoudDog.new(LoudDog)과 같고, LoudDog 'new' 키가 없지만
-- 메타테이블에서 __index = Dog이기 때문에 Dog.new(LoudDog)으로
-- 변환됩니다.
-- 결과: seymour의 메타테이블은 LoudDog이고 LoudDog.__index
-- LoudDog입니다. 따라서 seymour.key seymour.key,
-- LoudDog.key, Dog.key와 같을 것이며, 지정한 키에 어떤 테이블이
-- 오든 상관없을 것입니다.
-- 4. 'makeSound' 키는 LoudDog에서 발견할 수 있습니다.
-- 이것은 LoudDog.makeSound(seymour)와 같습니다.
-- <EFBFBD>ʿ<EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD> Ŭ<><C5AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> new()<29><> <20><><EFBFBD><EFBFBD> Ŭ<><C5AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> new()<29><> <20><><EFBFBD><EFBFBD><EFBFBD>մϴ<D5B4>.
-- 필요할 경우, 하위 클래스의 new()는 기반 클래스의 new()와 유사합니다.
function LoudDog:new()
newObj = {}
-- set up newObj
@@ -333,91 +333,91 @@ function LoudDog:new()
end
----------------------------------------------------
-- 4. <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
-- 4. 모듈
----------------------------------------------------
--[[ <EFBFBD><EFBFBD><EFBFBD><20>ּ<EFBFBD><D6BC><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD> <20><> <20><>ũ<EFBFBD><C5A9>Ʈ<EFBFBD><C6AE> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>κ<EFBFBD><CEBA><EFBFBD>
-- <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>°<EFBFBD> <20>˴ϴ<CBB4>.
--[[ 여기서 주석을 제거하면 이 스크립트의 나머지 부분은
-- 실행 가능한 상태가 됩니다.
```
```lua
-- mod.lua <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>ٰ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>ô<EFBFBD>.
-- mod.lua 파일의 내용이 다음과 같다고 가정해 봅시다.
local M = {}
local function sayMyName()
print('<EFBFBD>̼ҷ<EFBFBD>')
print('이소룡')
end
function M.sayHello()
print('<EFBFBD>ȳ<EFBFBD><EFBFBD>ϼ<EFBFBD><EFBFBD><EFBFBD>')
print('안녕하세요')
sayMyName()
end
return M
-- <EFBFBD><EFBFBD> <20>ٸ<EFBFBD> <20><><EFBFBD>Ͽ<EFBFBD><CFBF><EFBFBD><EFBFBD><EFBFBD> mod.lua<75><61> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>̿<EFBFBD><CCBF><EFBFBD> <20><> <20>ֽ<EFBFBD><D6BD>ϴ<EFBFBD>.
local mod = require('mod') -- mod.lua <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
-- 또 다른 파일에서는 mod.lua의 기능을 이용할 수 있습니다.
local mod = require('mod') -- mod.lua 파일을 실행
-- require<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>Խ<EFBFBD>Ű<EFBFBD><C5B0> ǥ<><C7A5>ȭ<EFBFBD><C8AD> <20><><EFBFBD><EFBFBD><EFBFBD>Դϴ<D4B4>.
-- require<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>մϴ<D5B4>: (ij<>̵<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>. <20>ϴ<EFBFBD> <20><><EFBFBD><EFBFBD>)
-- require는 모듈을 포함시키는 표준화된 방법입니다.
-- require는 다음과 같이 동작합니다: (캐싱돼 있지 않을 경우. 하단 참조)
local mod = (function ()
<mod.lua<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>>
<mod.lua 내용>
end)()
-- mod.lua<EFBFBD><EFBFBD> <20>Լ<EFBFBD><D4BC><EFBFBD> <20><><EFBFBD><EFBFBD>ó<EFBFBD><C3B3> <20>ǹǷ<C7B9> mod.lua <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
-- <EFBFBD>ۿ<EFBFBD><EFBFBD><EFBFBD> <20><> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>.
-- mod.lua가 함수의 본문처럼 되므로 mod.lua 안의 지역 멤버는
-- 밖에서 볼 수 없습니다.
-- <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ڵ尡 <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD> <20><><EFBFBD><EFBFBD> mod<EFBFBD><EFBFBD> mod.lua<EFBFBD><EFBFBD> M<><4D> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Դϴ<D4B4>.
mod.sayHello() -- <EFBFBD>̼ҷ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>λ縦 <20>dzܴϴ<DCB4>.
-- 다음 코드가 동작하는 것은 mod mod.lua의 M과 같기 때문입니다.
mod.sayHello() -- 이소룡 씨에게 인사를 건넵니다.
-- <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ڵ带 <20><><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>߻<EFBFBD><DFBB>մϴ<D5B4>.
-- sayMyName<EFBFBD><EFBFBD> mod.lua <EFBFBD>ȿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϱ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Դϴ<D4B4>:
mod.sayMyName() -- <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
-- 다음 코드를 실행하면 오류가 발생합니다.
-- sayMyName mod.lua 안에서만 존재하기 때문입니다:
mod.sayMyName() -- 오류
-- require<EFBFBD><EFBFBD> <20><>ȯ<EFBFBD><C8AF><EFBFBD><EFBFBD> ij<>̵ǹǷ<C7B9> require<72><65> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD>
-- <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ִ<EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>˴ϴ<CBB4>.
-- require의 반환값은 캐싱되므로 require를 여러 번 실행해도
-- 파일은 최대 한 번만 실행됩니다.
-- mod2.lua<EFBFBD><EFBFBD> "print('Hi')"<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ִٰ<D6B4> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>ô<EFBFBD>.
local a = require('mod2') -- Hi!<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
local b = require('mod2') -- print<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>. a=b
-- mod2.lua "print('Hi')"가 들어 있다고 가정해 봅시다.
local a = require('mod2') -- Hi!를 출력
local b = require('mod2') -- print를 실행하지 않음. a=b
-- dofile<EFBFBD><EFBFBD> require<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ij<><C4B3><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ʽ<EFBFBD><CABD>ϴ<EFBFBD>:
-- dofile require와 비슷하지만 캐싱을 하지 않습니다:
dofile('mod2') --> Hi!
dofile('mod2') --> Hi! (require<EFBFBD><EFBFBD> <20>޸<EFBFBD> <20>ٽ<EFBFBD> <20>ѹ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
dofile('mod2') --> Hi! (require와 달리 다시 한번 실행됨)
-- loadfile<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>о<EFBFBD><D0BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ʽ<EFBFBD><CABD>ϴ<EFBFBD>
f = loadfile('mod2') -- f()<EFBFBD><EFBFBD> ȣ<><C8A3><EFBFBD>ؾ<EFBFBD> mod2.lua<75><61> <20><><EFBFBD><EFBFBD><EFBFBD>˴ϴ<CBB4>.
-- loadfile은 루아 파일을 읽어들이지만 실행하지는 않습니다
f = loadfile('mod2') -- f()를 호출해야 mod2.lua가 실행됩니다.
-- loadstring<EFBFBD><EFBFBD> <20><><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD> <20><><EFBFBD><EFBFBD> loadfile<EFBFBD>Դϴ<EFBFBD>.
g = loadstring('print(343)') -- <EFBFBD>Լ<EFBFBD><EFBFBD><EFBFBD> <20><>ȯ<EFBFBD>մϴ<D5B4>.
g() -- 343<EFBFBD><EFBFBD> <20><><EFBFBD>µ˴ϴ<CBB4>. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ƹ<EFBFBD><C6B9>͵<EFBFBD> <20><><EFBFBD>µ<EFBFBD><C2B5><EFBFBD> <20>ʽ<EFBFBD><CABD>ϴ<EFBFBD>.
-- loadstring은 문자열에 대한 loadfile입니다.
g = loadstring('print(343)') -- 함수를 반환합니다.
g() -- 343이 출력됩니다. 그전까지는 아무것도 출력되지 않습니다.
--]]
```
## <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڷ<EFBFBD>
## 참고자료
<EFBFBD><EFBFBD><EFBFBD>Ƹ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߴ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <a href="http://love2d.org/">Love 2D <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD></a><EFBFBD><EFBFBD> <20>̿<EFBFBD><CCBF><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20>־<EFBFBD><D6BE><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Դϴ<D4B4>. <20>̰<EFBFBD><CCB0><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD>Ƹ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Դϴ<D4B4>.
루아를 배우는 일이 흥미진진했던 이유는 <a href="http://love2d.org/">Love 2D 게임 엔진</a>을 이용해
게임을 만들 수 있었기 때문입니다. 이것이 제가 루아를 배운 이유입니다.
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <a href="http://nova-fusion.com/2012/08/27/lua-for-programmers-part-1/">BlackBulletIV<EFBFBD><EFBFBD> "<22><><EFBFBD>α׷<CEB1><D7B7>Ӹ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>"</a><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߽<EFBFBD><EFBFBD>ϴ<EFBFBD>. <20>״<EFBFBD><D7B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <a href="http://www.lua.org/pil/contents.html">"<EFBFBD><EFBFBD><EFBFBD>α׷<EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>"</a> å<><C3A5> <20>о<EFBFBD><D0BE><EFBFBD><EFBFBD>ϴ<EFBFBD>.
<EFBFBD>׷<EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>Ƹ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>.
저는 <a href="http://nova-fusion.com/2012/08/27/lua-for-programmers-part-1/">BlackBulletIV의 "프로그래머를 위한 루아"</a>
시작했습니다. 그다음으로 공식 <a href="http://www.lua.org/pil/contents.html">"프로그래밍 루아"</a> 책을 읽었습니다.
그렇게 루아를 배웠습니다.
lua-users.org<EFBFBD><EFBFBD> <20>ִ<EFBFBD> <a href="http://lua-users.org/files/wiki_insecure/users/thomasl/luarefv51.pdf">ª<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD>۷<EFBFBD><DBB7><EFBFBD></a><EFBFBD><EFBFBD>
<EFBFBD>о<EFBFBD><EFBFBD>θ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>𸣰ڽ<F0B8A3B0><DABD>ϴ<EFBFBD>.
lua-users.org에 있는 <a href="http://lua-users.org/files/wiki_insecure/users/thomasl/luarefv51.pdf">짧은 루아 레퍼런스</a>
읽어두면 도움될지도 모르겠습니다.
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ǥ<><C7A5> <20><><EFBFBD>̺귯<CCBA><EAB7AF><EFBFBD><EFBFBD> <20><><EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD> <20>ٷ<EFBFBD><D9B7><EFBFBD> <20>ʾҽ<CABE><D2BD>ϴ<EFBFBD>.
여기서는 표준 라이브러리에 관해서는 다루지 않았습니다.
* <a href="http://lua-users.org/wiki/StringLibraryTutorial">string <EFBFBD><EFBFBD><EFBFBD>̺귯<EFBFBD><EFBFBD></a>
* <a href="http://lua-users.org/wiki/TableLibraryTutorial">table <EFBFBD><EFBFBD><EFBFBD>̺귯<EFBFBD><EFBFBD></a>
* <a href="http://lua-users.org/wiki/MathLibraryTutorial">math <EFBFBD><EFBFBD><EFBFBD>̺귯<EFBFBD><EFBFBD></a>
* <a href="http://lua-users.org/wiki/IoLibraryTutorial">io <EFBFBD><EFBFBD><EFBFBD>̺귯<EFBFBD><EFBFBD></a>
* <a href="http://lua-users.org/wiki/OsLibraryTutorial">os <EFBFBD><EFBFBD><EFBFBD>̺귯<EFBFBD><EFBFBD></a>
* <a href="http://lua-users.org/wiki/StringLibraryTutorial">string 라이브러리</a>
* <a href="http://lua-users.org/wiki/TableLibraryTutorial">table 라이브러리</a>
* <a href="http://lua-users.org/wiki/MathLibraryTutorial">math 라이브러리</a>
* <a href="http://lua-users.org/wiki/IoLibraryTutorial">io 라이브러리</a>
* <a href="http://lua-users.org/wiki/OsLibraryTutorial">os 라이브러리</a>
<EFBFBD>׳<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20><>ü<EFBFBD><C3BC> <20><>ȿ<EFBFBD><C8BF> <20><><EFBFBD><EFBFBD> <20><><EFBFBD>α׷<CEB1><D7B7>Դϴ<D4B4>. <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
learn.lua<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> "lua learn.lua"<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!
그나저나 이 파일 전체는 유효한 루아 프로그램입니다. 이 파일을
learn.lua로 저장한 후 "lua learn.lua"를 실행해 보세요!
<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> tylerneylon.com<EFBFBD><EFBFBD> ó<><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><20><><EFBFBD≯<EFBFBD>,
<a href="https://gist.github.com/tylerneylon/5853042">Github<EFBFBD><EFBFBD> Gist</a><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Ȯ<><C8AE><EFBFBD><EFBFBD> <20><> <20>ֽ<EFBFBD><D6BD>ϴ<EFBFBD>.
<EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD> <20><><EFBFBD>ſ<EFBFBD> <20>ð<EFBFBD><C3B0><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!
이 글은 tylerneylon.com에 처음으로 써본 글이며,
<a href="https://gist.github.com/tylerneylon/5853042">Github Gist</a>에서도 확인할 수 있습니다.
루아로 즐거운 시간을 보내세요!