diff options
author | Steven Barth <steven@midlink.org> | 2008-08-29 23:26:01 +0000 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2008-08-29 23:26:01 +0000 |
commit | ffd5c4ec656bd3f216c66b43587abcfdaf2b5c37 (patch) | |
tree | 243656197dd59fbb2b8d3d0af8928bf8700c26ed /libs/core | |
parent | 5cfda95377accd59f488868180b17ca86327839d (diff) |
General optimizations, simplifications and improvements
Diffstat (limited to 'libs/core')
-rw-r--r-- | libs/core/luasrc/util.lua | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/libs/core/luasrc/util.lua b/libs/core/luasrc/util.lua index 260fc16a00..6cefb8ec9b 100644 --- a/libs/core/luasrc/util.lua +++ b/libs/core/luasrc/util.lua @@ -24,8 +24,21 @@ limitations under the License. ]]-- +local io = require "io" +local table = require "table" +local debug = require "debug" +local string = require "string" +local coroutine = require "coroutine" + +local getmetatable, setmetatable = getmetatable, setmetatable +local getfenv, setfenv = getfenv, setfenv +local rawget, rawset, unpack = rawget, rawset, unpack +local tostring, type, assert = tostring, type, assert +local ipairs, pairs, loadstring = ipairs, pairs, loadstring +local require, pcall, xpcall = require, pcall, xpcall + --- LuCI utility functions. -module("luci.util", package.seeall) +module "luci.util" -- -- Pythonic string formatting extension @@ -63,14 +76,10 @@ function class(base) local class = {} local create = function(class, ...) - local inst = {} - setmetatable(inst, {__index = class}) + local inst = setmetatable({}, {__index = class}) if inst.__init__ then - local stat, err = copcall(inst.__init__, inst, ...) - if not stat then - error(err) - end + inst:__init__(...) end return inst @@ -284,8 +293,7 @@ end -- @param str String value containing whitespace padded data -- @return String value with leading and trailing space removed function trim(str) - local s = str:gsub("^%s*(.-)%s*$", "%1") - return s + return (str:gsub("^%s*(.-)%s*$", "%1")) end --- Parse certain units from the given string and return the canonical integer @@ -413,9 +421,7 @@ function clone(object, deep) copy[k] = v end - setmetatable(copy, getmetatable(object)) - - return copy + return setmetatable(copy, getmetatable(object)) end @@ -473,11 +479,11 @@ function serialize_data(val, seen) elseif type(val) == "number" then return val elseif type(val) == "string" then - return string.format("%q", val) + return "%q" % val elseif type(val) == "boolean" then return val and "true" or "false" elseif type(val) == "function" then - return string.format("loadstring(%q)", get_bytecode(val)) + return "loadstring(%q)" % get_bytecode(val) elseif type(val) == "table" then return "{ " .. _serialize_table(val, seen) .. " }" else @@ -691,7 +697,7 @@ end --- Returns the absolute path to LuCI base directory. -- @return String containing the directory path function libpath() - return luci.fs.dirname(require("luci.debug").__file__) + return require "luci.fs".dirname(require "luci.debug".__file__) end |