我有一个 lua 函数来尝试将当前播放歌曲的持续时间(例如 hh:mm:ss 转换为秒)。
function toSeconds (inputstr)
local mytable = string.gmatch(inputstr, "([^"..":".."]+)");
local conversion = { 60, 60, 24}
local seconds = 0;
--iterate backwards
local count = 0;
for i=1, v in mytable do
count = i+1
end
for i=1, v in mytable do
mytable[count-i]
seconds = seconds + v*conversion[i]
end
return seconds
end
为了将其添加os.time
到获取歌曲的估计结束时间。
但是时间可能会丢失,或者分钟可能会在短途上丢失。
当针对https://www.lua.org/cgi-bin/demo运行时,我得到的只是input:10: 'do' expected near 'in'
对于测试脚本
function toSeconds (inputstr)
local mytable = string.gmatch(inputstr, "([^"..":".."]+)");
local conversion = { 60, 60, 24}
local seconds = 0;
--iterate backwards
local count = 0;
for i=1, v in mytable do
count = i+1
end
for i=1, v in mytable do
mytable[count-i]
seconds = seconds + v*conversion[i]
end
return seconds
end
print(toSeconds("1:1:1")