lua-users home
lua-l archive

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

I have worked up a patch (against 5.1.1) that removes auto-casting between numbers and strings. It currently works in most of the major cases (arithmetic, concatenation, #) although there's still some work to do in the libraries.

The reason I'm posting about it is to ask if anyone else is interested. Specifically:

1. Would anyone like the patch? If so, I'd check the library cases a bit more carefully and document what I did.

2. Would it be interesting enough to make it a compile-time option? From looking at the code it would seem possible to replace internal calls to various tonumber and tostring options with "casttonumber" and "casttostring", which could have appropriate compile-time definitions.

Motivation for the patch: I don't like automatic casting; it hides bugs. I also think it rarely[1] helps users, and if it does (e.g. in a config file), then you can do the auto-casting yourself (e.g. read a config file, and call "to<type>(v)" on each value you read).

[1]For example, print is one function I've left alone. This is an example of the fine line in Lua between auto-casting and intentionally calling a tostring method.

-- | The old cliches are the best