Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

result of tonumber depends on the locale #19

Closed
dfern opened this issue Jul 11, 2012 · 1 comment
Closed

result of tonumber depends on the locale #19

dfern opened this issue Jul 11, 2012 · 1 comment

Comments

@dfern
Copy link

dfern commented Jul 11, 2012

The Lua functions tonumber and tostring use a dot as decimal separator. With lgi, it depends on the locale.

My locale is pt_br, the decimal separator is comma, so I get some unespected results. For example, running

print(tonumber("3.2"))  --> 3.2
print(tonumber("3,2"))  --> nil

local lgi = require 'lgi'
print(tonumber("3.2"))  --> 3.2
print(tonumber("3,2"))  --> nil

local Gtk = lgi.Gtk
print(tonumber("3.2"))  --> nil
print(tonumber("3,2"))  --> 3,2

results in
3.2
nil
3.2
nil
nil
3,2

Note that the result changes only after "local Gtk = lgi.Gtk".

@pavouk
Copy link
Collaborator

pavouk commented Jul 11, 2012

Fixed in git/master. setlocale() was called automatically by gtk_init(), but fortunately gtk contains gtk_disable_setlocale() call, which avoids this auto-cleverness. Similar fix was employed in gstreamer's override file, where numeric category locale was reverted to 'C'. However, there might be other less common libraries in gnome stack or even outside which do automatically call setlocale(LC_ALL, ""). I don't know how to handle this problem in a generic way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants