식별자(identifier)는 변수명이나 함수명 등을 만들때 사용된다. 루아의 식별자를 만드는 규칙은 다음과 같다. (C/C++과 동일하다.)


  1. 영어 대소문자(a~z, A~Z), 숫자(0~9), 언더바(_)로만 조합한다.

  2. 숫자로 시작하거나 공백문자를 포함할 수 없다.

  3. 미리 정의된 예약어(keyword)는 사용하면 안된다.


다른 언어에서와 마찬가지로 식별자는 대소문자를 구별한다. 즉, 대문자 A와 소문자 a는 서로 다른 것으로 구별된다. 식별자는 에를 들면 다음과 같은 것들이다.


x, vla, number, _hello, abc, id123, ch_4_5, name_of_that, _image, __sound


루아의 예약어는 프로그램에서 의미를 갖는 단어로서 다음과 같은 것들이 있다.


and, break, do, else, elseif, end, false, for, function, if, in local, nil, not, or, repeat, return, then, true, until, while


또한 예약어 외에 전역 함수(혹은 객체)에 사용되는 식별자도 사용하면 안되며 다음과 같은 것들이 있다.


_G, _VERSION, getmetatable, tostring, assert, io, rawlen, string, load, bit32, pairs, rawset, select, coroutine, tonumber, next, type, table, xpcall, error, utf8, debug, collectgarbage, math, rawget, os, pcall, ipairs, rawequal, print, setmetatable


이러한 규칙에 따라서 식별자를 만들어야 한다.



Posted by 살레시오
,