모듈:Coutput

--출력할 값을 담고 있다가 한번에 출력하는 모듈
local p = {}

function p.print(o, value)
if type(o) ~= "table" then return p end
if type(value) == "nil" then return p end
o[#o+1]=tostring(value) -- 입력받은 대로 하나씩 저장
return p --자기 자신을 리턴
end

function p.printf(o, formatstring, ...)
if type(o) ~= "table" then return p end
--if type(value) == "nil" then return p end
o[#o+1]=string.format(formatstring, ...) -- 입력받은 대로 하나씩 저장
return p --자기 자신을 리턴
end


function p.printall(o)
return table.concat(o, "", 1, #o) -- o 테이블에 저장된 값을 모아서 리턴
end

function p.example()
--[[
local t ={}
p.print(t, "안녕하세요!
")
p.print(t, nil)
p.print(t, "1+1=")
p.print(t, 1+1)
return p.printall(t)
]]
p:print("안녕하세요!
")
p:print(nil)
p:print("1+1=")
p:print(1+1)
return p:printall()
end

return p