[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Is string always same as number? (the consistency of lua)
- From: Drake Wilson <drake@...>
- Date: Fri, 11 Feb 2011 06:02:23 -0700
Quoth steve donovan <steve.j.donovan@gmail.com>, on 2011-02-11 13:58:03 +0200:
> Well, that's a definite no-no if it depends on some essentially random event!
>
> I must say I've never used coercion-to-number, always explicit
> tonumber() which gives a non-fatal result.
Note that tonumber() and tostring() have the same locale dependency
when doing that conversion. This is a result of trying to be Simple
and defer as many things as possible to the underlying C. And it
works, in that the canonical Lua implementation is small and simple
and reuses a lot of existing library functionality rather than having
N incompatible functions flying around doing almost the same thing.
Except that the platforms were Not Quite Designed For This.
$ LC_ALL=fr_FR.UTF-8 lua
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
> a = '1.3'; b = 1.3
> =tonumber(a)
1.3
> os.setlocale('')
> return tonumber(a)
nil
> return tostring(b)
1,3
>
You can't really win here, as far as I can tell. Runtimes that want
to be more predictable wind up including their own routines for just
about anything that doesn't actually depend on the OS, because having
a dependency on the C standard library turns out to be a nightmare for
a large number of functions for reasons like this. Or you can just
take the hit and assume the user won't set LC_NUMERIC to anything
other than C, or...
> steve d.
---> Drake Wilson
- References:
- Re: Is string always same as number? (the consistency of lua), steve donovan
- Re: Is string always same as number? (the consistency of lua), Axel Kittenberger
- Re: Is string always same as number? (the consistency of lua), Philippe Lhoste
- Re: Is string always same as number? (the consistency of lua), Xavier Wang
- Re: Is string always same as number? (the consistency of lua), Dirk Laurie
- Re: Is string always same as number? (the consistency of lua), Miles Bader
- Re: Is string always same as number? (the consistency of lua), Miles Bader
- Re: Is string always same as number? (the consistency of lua), Dirk Laurie
- Re: Is string always same as number? (the consistency of lua), Drake Wilson
- Re: Is string always same as number? (the consistency of lua), steve donovan