lua-users home
lua-l archive

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


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