Commit c90a3e02 authored by Pierre Ynard's avatar Pierre Ynard

lua: add and use us_tonumber() for decimal numbers

Closes #5705
parent 4b709298
...@@ -464,7 +464,7 @@ end ...@@ -464,7 +464,7 @@ end
function rate(name,client,value) function rate(name,client,value)
local input = vlc.object.input() local input = vlc.object.input()
if name == "rate" then if name == "rate" then
vlc.var.set(input, "rate", tonumber(value)) vlc.var.set(input, "rate", common.us_tonumber(value))
elseif name == "normal" then elseif name == "normal" then
vlc.var.set(input,"rate",1) vlc.var.set(input,"rate",1)
else else
......
...@@ -46,6 +46,19 @@ function table_copy(t) ...@@ -46,6 +46,19 @@ function table_copy(t)
return c return c
end 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 -- strip leading and trailing spaces
function strip(str) function strip(str)
return string.gsub(str, "^%s*(.-)%s*$", "%1") return string.gsub(str, "^%s*(.-)%s*$", "%1")
...@@ -119,9 +132,9 @@ function seek(value) ...@@ -119,9 +132,9 @@ function seek(value)
local input = vlc.object.input() local input = vlc.object.input()
if input ~= nil and value ~= nil then if input ~= nil and value ~= nil then
if string.sub(value,-1) == "%" 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 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 if string.sub(value,1,1) == "+" or string.sub(value,1,1) == "-" then
vlc.var.set(input,"position",vlc.var.get(input,"position") + posPercent) vlc.var.set(input,"position",vlc.var.get(input,"position") + posPercent)
else else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment