[vlc-commits] lua: add and use us_tonumber() for decimal numbers

Pierre Ynard git at videolan.org
Sat Jan 7 17:59:21 CET 2012


vlc | branch: master | Pierre Ynard <linkfanel at yahoo.fr> | Sat Jan  7 17:58:09 2012 +0100| [c90a3e02568368f55f454aee7c89ed57a945ed17] | committer: Pierre Ynard

lua: add and use us_tonumber() for decimal numbers

Closes #5705

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c90a3e02568368f55f454aee7c89ed57a945ed17
---

 share/lua/intf/cli.lua            |    2 +-
 share/lua/intf/modules/common.lua |   17 +++++++++++++++--
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/share/lua/intf/cli.lua b/share/lua/intf/cli.lua
index 265b938..ed2a685 100644
--- a/share/lua/intf/cli.lua
+++ b/share/lua/intf/cli.lua
@@ -464,7 +464,7 @@ end
 function rate(name,client,value)
     local input = vlc.object.input()
     if name == "rate" then
-        vlc.var.set(input, "rate", tonumber(value))
+        vlc.var.set(input, "rate", common.us_tonumber(value))
     elseif name == "normal" then
         vlc.var.set(input,"rate",1)
     else
diff --git a/share/lua/intf/modules/common.lua b/share/lua/intf/modules/common.lua
index 5744427..ca51344 100644
--- a/share/lua/intf/modules/common.lua
+++ b/share/lua/intf/modules/common.lua
@@ -46,6 +46,19 @@ function table_copy(t)
     return c
 end
 
+-- tonumber() for decimals number, using a dot as decimal separator
+-- regardless of the system locale 
+function us_tonumber(str)
+    local i, d = string.match(str, "([+-]?%d*)%.?(%d*)")
+    if i == nil or i == "" then
+        i = "0"
+    end
+    if d == nil or d == "" then
+        d = "0"
+    end
+    return tonumber(i) + tonumber(d)/(10^string.len(d))
+end
+
 -- strip leading and trailing spaces
 function strip(str)
     return string.gsub(str, "^%s*(.-)%s*$", "%1")
@@ -119,9 +132,9 @@ function seek(value)
     local input = vlc.object.input()
     if input ~= nil and value ~= nil then
         if string.sub(value,-1) == "%" then
-            local number = tonumber(string.sub(value,1,-2))
+            local number = us_tonumber(string.sub(value,1,-2))
             if number ~= nil then
-                local posPercent = tonumber( string.sub(value,1,-2))/100.
+                local posPercent = number/100.
                 if string.sub(value,1,1) == "+" or string.sub(value,1,1) == "-" then
                     vlc.var.set(input,"position",vlc.var.get(input,"position") + posPercent)
                 else



More information about the vlc-commits mailing list