[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How determine data type used in function argument?
- From: Rob Kendrick <rjek@...>
- Date: Mon, 20 Jun 2022 14:46:42 +0100
On Mon, Jun 20, 2022 at 08:24:04PM +0700, Budi wrote:
> How to determine the correct data type used in function argument? e.g.
>
> function incr (n)
> ------------------- which type of what?
> n = n .. "foo"
> n = n + 1
> end
Something like this?
function incr(n)
if type(n) == "string" then
n = n .. "foo"
elseif type(n) == "number" then
n = n + 1
else
return nil, "unhandled type " .. type(n)
end
return n
end
B.