| 1 |
local lfs = require("lfs") |
| 2 |
|
| 3 |
function string.split(self, pat) |
| 4 |
pat = pat or "%s+" |
| 5 |
local st, g = 1, self:gmatch("()("..pat..")") |
| 6 |
local function l_getter(self, segs, seps, sep, cap1, ...) |
| 7 |
st = sep and seps + #sep |
| 8 |
return self:sub(segs, (seps or 0) - 1), cap1 or sep, ... |
| 9 |
end |
| 10 |
local function l_splitter(self) |
| 11 |
if st then return l_getter(self, st, g()) end |
| 12 |
end |
| 13 |
return l_splitter, self |
| 14 |
end |
| 15 |
|
| 16 |
function main() |
| 17 |
|
| 18 |
local version = lfs._VERSION:lower():gsub("luafilesystem *","") |
| 19 |
local factorA = { 1000000, 1000, 1} |
| 20 |
|
| 21 |
local idx = 0 |
| 22 |
local num = 0 |
| 23 |
for s in version:split("%.") do |
| 24 |
local i,j = s:find("%d+") |
| 25 |
s = s:sub(i,j) |
| 26 |
idx = idx + 1 |
| 27 |
num = (tonumber(s) or 0)*factorA[idx] + num |
| 28 |
if (idx >= #factorA) then break end |
| 29 |
end |
| 30 |
print(num) |
| 31 |
end |
| 32 |
|
| 33 |
main() |