모듈:연습장/배우는사람/Bananas: 두 판 사이의 차이

내용 삭제됨 내용 추가됨
새 문서: local p = {} ----------------------------------------------------------------------------------------------------------- function p.has_fruit(param) local name = param.args[1]...
(차이 없음)

2018년 5월 18일 (금) 13:32 판

local p = {}


-----------------------------------------------------------------------------------------------------------
function p.has_fruit(param)
    local name = param.args[1]
    local num_bananas = param.args.bananas
    local num_apples = param.args.apples
    local num_cherries = param.args.cherries

    if not name then return '' end
    local result = name .. ' has'
    if num_bananas then 
        result = result .. ' ' .. num_bananas .. ' bananas' 
    end
    if num_apples then 
       if num_bananas then   
         result = result .. ', ' .. num_apples .. ' apples' 
       else
          result = result .. ' ' .. num_apples .. ' apples' 
        end
    end
    if num_cherries then 
        if num_bananas or num_apples then 
             result = result .. ', ' .. num_cherries.. ' cherries' 
        else
             result = result .. ' ' .. num_cherries.. ' cherries' 
        end
    end
    return result
end

-- Mixing regular args with named args and optional named args
-- Used like: {{#invoke:BananasArgs|has_fruit|Fred|bananas=5|cherries=7}}
--function p.has_fruit(frame)
--	local name = frame.args[1]
--	local num_bananas = frame.args.bananas
--	local num_apples = frame.args.apples
--	local num_cherries = frame.args.cherries
--	
--	if not name then return '' end
--	local result = name .. ' has:'
--	if num_bananas then result = result .. ' ' .. num_bananas .. ' bananas' end
--	if num_apples then result = result .. ' ' .. num_apples .. ' apples' end
--	if num_cherries then result = result .. ' ' .. num_cherries .. ' cherries' end
--	return result
--end
-----------------------------------------------------------------------------------------------------------
function p.count_fruit(param)
   local num_bananas = param.args.bananas
   local num_apples = param.args.apples
   local num_pears = param.args.pears

  return 'There are ' .. num_bananas .. ' bananas, ' .. num_apples .. ' apples, and ' .. num_pears .. ' pears.'  
end

-- Named arguments, used like: {{#invoke:BananasArgs|count_fruit|bananas=5|apples=3}}
--function p.count_fruit(frame)
--	local num_bananas = frame.args.bananas
--	local num_apples = frame.args.apples
--	return 'I have ' .. num_bananas .. ' bananas and ' .. num_apples .. ' apples'
--end

-----------------------------------------------------------------------------------------------------------

function p.add(param)
    local num1 = tonumber(param.args[1])
    local num2 = tonumber(param.args[2])
    return num1 + num2
end

function p.subtract(param)
    local num1 = tonumber(param.args[1])
    local num2 = tonumber(param.args[2])
    return num1 - num2
end

function p.multiply(param)
    local num1 = tonumber(param.args[1])
    local num2 = tonumber(param.args[2])
    return num1 * num2
end

function p.divide(param)
    local num1 = tonumber(param.args[1])
    local num2 = tonumber(param.args[2])
    return num1 / num2
end


-- Two arguments, used like: {{#invoke:BananasArgs|add|5|3}}
--function p.add(frame)
--	local num1 = tonumber(frame.args[1])
--	local num2 = tonumber(frame.args[2])
--	return num1 + num2
--end

-----------------------------------------------------------------------------------------------------------

function p.hello2(name)
   local name1=name.args[1]
   return "안녕하세요, " .. name1 .. "!"
end

function p.hello3(name)
  local name1=name.args[1]
   return "안녕하세요, " .. name1 .."!"
end

function p.hello4(name)
   local name1=name.args[1]
   return "안녕하세요, " .. name1.."!"
end

-- One argument, used like: {{#invoke:BananasArgs|hello|Fred}} 
--function p.hello2(frame)
--	local name = frame.args[1] -- in this example, args[1] is the word Fred 
--	return "Hello, " .. name .. "!" -- .. name .. replace by the word Fred
--end

-----------------------------------------------------------------------------------------------------------

function p.hello()
   return "안녕하세요, 루아입니다."
end

return p

-- 헬로 월드!
-- local p = {}
 
-- function p.hello()
--    return "Hello, world!"
--end
 
--return p