
해결 방법은 두 가지가 있습니다.
1. 오버로드 함수에서 string 타입의 인수를 처리하는 로직을 추가합니다. 예를 들어, string 타입의 인수를 합치기 전에 string을 number로 변환하는 함수를 만들 수 있습니다.
#hostingforum.kr
lua
local uopz = require("uopz")
local function add(a, b)
if type(a) == "string" and type(b) == "string" then
return a .. b
elseif type(a) == "string" then
return a .. tostring(b)
elseif type(b) == "string" then
return tostring(a) .. b
else
return a + b
end
end
uopz.overloads(add, {
{"number", "number"},
{"string", "string"}
})
2. 오버로드 함수를 두 개로 분리하여, string 타입의 인수를 처리하는 함수를 별도로 만들 수 있습니다.
#hostingforum.kr
lua
local uopz = require("uopz")
local function add(a, b)
return a + b
end
local function add_string(a, b)
return a .. b
end
uopz.overloads(add, {
{"number", "number"}
})
uopz.overloads(add_string, {
{"string", "string"}
})
2025-04-30 12:50