Optimized uvl.datatypes
This commit is contained in:
parent
c287c8ca7e
commit
9a8cd55c36
1 changed files with 14 additions and 11 deletions
|
@ -14,11 +14,14 @@ $Id$
|
|||
|
||||
]]--
|
||||
|
||||
module( "luci.uvl.datatypes", package.seeall )
|
||||
local fs = require "luci.fs"
|
||||
local ip = require "luci.ip"
|
||||
local math = require "math"
|
||||
local util = require "luci.util"
|
||||
|
||||
require("luci.fs")
|
||||
require("luci.ip")
|
||||
require("luci.util")
|
||||
local tonumber = tonumber
|
||||
|
||||
module "luci.uvl.datatypes"
|
||||
|
||||
|
||||
function boolean( val )
|
||||
|
@ -59,7 +62,7 @@ end
|
|||
|
||||
function ip4addr( val )
|
||||
if val then
|
||||
return luci.ip.IPv4(val) and true or false
|
||||
return ip.IPv4(val) and true or false
|
||||
end
|
||||
|
||||
return false
|
||||
|
@ -72,7 +75,7 @@ end
|
|||
|
||||
function ip6addr( val )
|
||||
if val then
|
||||
return luci.ip.IPv6(val) and true or false
|
||||
return ip.IPv6(val) and true or false
|
||||
end
|
||||
|
||||
return false
|
||||
|
@ -102,7 +105,7 @@ function macaddr( val )
|
|||
"^[a-fA-F0-9]+:[a-fA-F0-9]+:[a-fA-F0-9]+:" ..
|
||||
"[a-fA-F0-9]+:[a-fA-F0-9]+:[a-fA-F0-9]+$"
|
||||
) then
|
||||
local parts = luci.util.split( val, ":" )
|
||||
local parts = util.split( val, ":" )
|
||||
|
||||
for i = 1,6 do
|
||||
parts[i] = tonumber( parts[i], 16 )
|
||||
|
@ -134,7 +137,7 @@ function string( val )
|
|||
end
|
||||
|
||||
function directory( val, seen )
|
||||
local s = luci.fs.stat( val )
|
||||
local s = fs.stat( val )
|
||||
seen = seen or { }
|
||||
|
||||
if s and not seen[s.ino] then
|
||||
|
@ -142,7 +145,7 @@ function directory( val, seen )
|
|||
if s.type == "directory" then
|
||||
return true
|
||||
elseif s.type == "link" then
|
||||
return directory( luci.fs.readlink(val), seen )
|
||||
return directory( fs.readlink(val), seen )
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -150,7 +153,7 @@ function directory( val, seen )
|
|||
end
|
||||
|
||||
function file( val, seen )
|
||||
local s = luci.fs.stat( val )
|
||||
local s = fs.stat( val )
|
||||
seen = seen or { }
|
||||
|
||||
if s and not seen[s.ino] then
|
||||
|
@ -158,7 +161,7 @@ function file( val, seen )
|
|||
if s.type == "regular" then
|
||||
return true
|
||||
elseif s.type == "link" then
|
||||
return file( luci.fs.readlink(val), seen )
|
||||
return file( fs.readlink(val), seen )
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue