X-Git-Url: http://git.archive.openwrt.org/?a=blobdiff_plain;f=libs%2Fuvl%2Fluasrc%2Fuvl%2Fdatatypes.lua;h=fc37fa3c6989dfa378760f4f8fc225aa4e7bc9fb;hb=77432eb0479ec101aaa2287394ec8751d589aed2;hp=e6a4c16887463728800535a0cf90f29dbdf60f41;hpb=35a529a5c56df3dbcd105f691d164f4f85283611;p=project%2Fluci.git diff --git a/libs/uvl/luasrc/uvl/datatypes.lua b/libs/uvl/luasrc/uvl/datatypes.lua index e6a4c1688..fc37fa3c6 100644 --- a/libs/uvl/luasrc/uvl/datatypes.lua +++ b/libs/uvl/luasrc/uvl/datatypes.lua @@ -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 ) @@ -26,6 +29,8 @@ function boolean( val ) return true elseif val == "0" or val == "no" or val == "off" or val == "false" then return true + elseif val == "" or val == nil then + return true end return false @@ -59,7 +64,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 +77,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 +107,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 +139,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 +147,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 +155,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 +163,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