lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 2012-10-23 12:07 AM, "乙振斐" <yizhenfei@gmail.com> wrote:
>
> Without static type checking, we may send wrong parameters to a function and we cannot find this mistake until the program crashes in run time.
> But if it is a huge program, we are not able to cover 100% codes in test, in this situation ,how can we prevent this problem?(say, pass wrong type parameters to a function)
>
> Sorry, I am a new comer with Lua, and it is the first time for me to learn a dynamic language, forgive me if this problem is ridiculous. But it really bothered me for a long time.
>
> Regards,
> Zhenfei Yi.

You can check with type() if you want to verify. Usually you shouldn't need to though. If something needs to be a number or string, use tonumber/tostring() or implicit conversions; if it's an object, just check if it has the methods you're interested in.