[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Proposal: strict type checking for patterns (Was: Number-to-string coercion gotcha)
- From: Dirk Laurie <dirk.laurie@...>
- Date: Thu, 3 Apr 2014 20:21:39 +0200
2014-03-30 11:36 GMT+02:00 Dirk Laurie <dirk.laurie@gmail.com>:
> But in the case of library functions whose inputs and outputs are in some
> cases numbers and other cases strings, it seems to me that supplying
> a number where a string is expected, or vice versa, is highly likely to be
> an error. And here it is not a matter of digging deeply into lua_tolstring,
> One could simply use different macros instead of luaL_checkstring
> and luaL_optstring that would do a strict check on lua_type before
> lua_tonumber or lua_tostring.
The above amounts to a proposal.
Lua library functions should not apply automatic number-to-string
coercion when the expected string parameter is a pattern. In that
case, when given anything whose type is not 'string', the routine
should throw an error.