[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua 5.3: 1 Month of use
- From: Dirk Laurie <dirk.laurie@...>
- Date: Thu, 6 Mar 2014 08:15:16 +0200
2014-03-04 18:45 GMT+02:00 Hisham <h@hisham.hm>:
Coming from such a respected member of the Lua community, these
comments have to be taken seriously. I have therefore taken the trouble
of patching Lua to try out the suggested feature before replying.
> On 4 March 2014 13:21, Dirk Laurie <dirk.laurie@gmail.com> wrote:
>> 2014-03-04 16:48 GMT+02:00 Andrew Starks <andrew.starks@trms.com>:
>>> Yes. My first observation was focusing on number's __tostring method
>>> defaulting to "%f" instead of "%.f".
>>
>> Actually, LUA_NUMBER_FMT defaults to "%.14g", hardwired. A clean
>> solution would be to make it settable via debug.number_format(s).
>
> That would be a huge step back in interoperability. I could see it
> breaking modules everywhere.
Lua 5.3.0 (work1) has three possible LUA_NUMBER_FMT
settings, depending on the floating point length, and uses
LUA_INTEGER_FMT for integers. What does that do
to interoperability?
> One might argue that this would be similar to other global changes /
> "monkey patching", but modules have ways to defend themselves from
> those. Changing the number format would make little unexpected
> behaviors pop up here and there (potentially in hard-to-spot corner
> cases), with no way to defend against.
If the feature is not actually invoked, the environment requiring the
modules stays the same, so the modules can't be broken this way.
"debug." in Lua code is not hard to spot.
>
> Also, it's not a debug feature. (Though I understand that the debug
> table is sometimes seen as the
> powerful-things-you-shouldn't-use-in-well-behaved-code table.)
Such as setting metatables for numbers, functions etc. One can
simply grep "debug" to sniff out suspect behaviour. Yes, people do that.
But it could well and truly be a debug feature. Every print statement
containing a float could carry a tag.
$ src/lua
Lua 5.3.0 (work1,lua_number_fmt) Copyright (C) 1994-2013 Lua.org, PUC-Rio
> print(1,2,3)
1 2 3
> print(1.0,2.0,3.0)
1.0 2.0 3.0
> debug.setnumberformat("DANGER! %.14g")
> print(1,2,3)
1 2 3
> print(1.0,2.0,3.0)
DANGER! 1 DANGER! 2 DANGER! 3
>