코딩 스타일
개요
선언 범위에 따른 이름 규칙
변수
-- Good
local Number = 1
_G.GlobalValue = 2
-- Bad
local number = 1
_G.globalValue = 2함수
함수의 인자와 반환값
연산자
들여쓰기와 줄바꿈
팀 프로젝트에서
Last updated
-- Good
local Number = 1
_G.GlobalValue = 2
-- Bad
local number = 1
_G.globalValue = 2Last updated
-- Good
local function SomeFunction()
local value = 3
if value >= 3 then
local someBoolean = false
end
end
-- Bad
local function SomeFunction()
local Value = 3
if Value >= 3 then
local SomeBoolean = false
end
end-- Good
local function SomeFunction()
print("Do Someting")
end
function _G.SomeFunction()
print("Do Someting")
end
-- Bad
local function someFunction()
print("Do Someting")
end
function _G.someFunction()
print("Do Someting")
end-- Good
local function Sum(numValue1, numValue2)
local result = numValue1 + numValue2
local isSuccess = (result ~= nil)
return isSuccess, result
end
-- Bad
local function Sum(NumValue1,NumValue2)
local result = NumValue1 + NumValue2
local isSuccess = (result ~= nil)
return isSuccess,result
end-- Good
local Sum = 1 + 5
local IsPositiveNumber = Sum > 0
if SomeValue == 1 && SomeValue == 2 then
print("Valid Value")
elseif SomeValue == 3 then
print("Value Exceeded)
else
print("Invalid Value"")
end
-- Bad
local Sum=1+5
local IsPositiveNumber=Sum>0
if SomeValue==1&&SomeValue==2 then
print("Valid Value")
elseif SomeValue==3 then
print("Value Exceeded)
else
print("Invalid Value"")
end-- Good
if someCondition1 then
if someCondition2 then
print("Correct!")
end
end
-- Bad
if someCondition1 then
if someCondition2 then
print("Correct!")
end
end-- Good
local NumberList =
{
1, 2, 3
}
for i = 1, 5 do
print(i)
end
-- Bad
local NumberList = {
1, 2, 3
}
for i = 1, 5 do print(i)
end