libs/core: Fixed luci.utils, Added missing in-line documentation
This commit is contained in:
parent
70b119b8ee
commit
b4ac19ca76
1 changed files with 34 additions and 18 deletions
|
@ -35,7 +35,7 @@ module("luci.util", package.seeall)
|
||||||
-- Creates a new class object which can be instantiated by calling itself.
|
-- Creates a new class object which can be instantiated by calling itself.
|
||||||
-- Any class functions or shared parameters can be attached to this object.
|
-- Any class functions or shared parameters can be attached to this object.
|
||||||
-- Attaching a table to the class object makes this table shared between
|
-- Attaching a table to the class object makes this table shared between
|
||||||
-- all instances of this class. For object paramters use the __init__ function.
|
-- all instances of this class. For object parameters use the __init__ function.
|
||||||
-- Classes can inherit member functions and values from a base class.
|
-- Classes can inherit member functions and values from a base class.
|
||||||
-- Class can be instantiated by calling them. All parameters will be passed
|
-- Class can be instantiated by calling them. All parameters will be passed
|
||||||
-- to the __init__ function of this class - if such a function exists.
|
-- to the __init__ function of this class - if such a function exists.
|
||||||
|
@ -94,24 +94,33 @@ end
|
||||||
-- Scope manipulation routines
|
-- Scope manipulation routines
|
||||||
--
|
--
|
||||||
|
|
||||||
--- Resets the scope of f doing a shallow copy of its scope into a new table
|
--- Replace a function scope with a shallow copy of itself
|
||||||
-- (ToDo: @param and @return)
|
-- This is useful if you want to get rid of several unwanted side effects
|
||||||
|
-- while changing the scope of a certain Lua function.
|
||||||
|
-- @param f Lua function
|
||||||
function resfenv(f)
|
function resfenv(f)
|
||||||
setfenv(f, clone(getfenv(f)))
|
setfenv(f, clone(getfenv(f)))
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Store given object associated with given key in the scope associated with
|
--- Store given object associated with given key in the scope of a function
|
||||||
-- the given identifier.
|
-- @param f Lua function
|
||||||
-- @param f Value containing the scope identifier
|
|
||||||
-- @param key String value containg the key of the object to store
|
-- @param key String value containg the key of the object to store
|
||||||
-- @param obj Object to store in the scope
|
-- @param obj Object to store in the scope
|
||||||
|
-- @see updfenv
|
||||||
|
-- @see resfenv
|
||||||
-- @return Always nil
|
-- @return Always nil
|
||||||
function extfenv(f, key, obj)
|
function extfenv(f, key, obj)
|
||||||
local scope = getfenv(f)
|
local scope = getfenv(f)
|
||||||
scope[key] = obj
|
scope[key] = obj
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Updates the scope of f with "extscope" (ToDo: docu)
|
--- Extend the scope of a function with the contents of a table
|
||||||
|
-- @param f Lua function
|
||||||
|
-- @param key String value containg the key of the object to store
|
||||||
|
-- @param obj Object to store in the scope
|
||||||
|
-- @see extfenv
|
||||||
|
-- @see resfenv
|
||||||
|
-- @return Always nil
|
||||||
function updfenv(f, extscope)
|
function updfenv(f, extscope)
|
||||||
update(getfenv(f), extscope)
|
update(getfenv(f), extscope)
|
||||||
end
|
end
|
||||||
|
@ -155,7 +164,7 @@ end
|
||||||
-- @param obj Value to write to stderr
|
-- @param obj Value to write to stderr
|
||||||
-- @return Boolean indicating wheather the write operation was successful
|
-- @return Boolean indicating wheather the write operation was successful
|
||||||
function perror(obj)
|
function perror(obj)
|
||||||
io.stderr:write(tostring(obj) .. "\n")
|
return io.stderr:write(tostring(obj) .. "\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Recursively dumps a table to stdout, useful for testing and debugging.
|
--- Recursively dumps a table to stdout, useful for testing and debugging.
|
||||||
|
@ -510,7 +519,16 @@ local oldpcall, oldxpcall = pcall, xpcall
|
||||||
coxpt = {}
|
coxpt = {}
|
||||||
setmetatable(coxpt, {__mode = "kv"})
|
setmetatable(coxpt, {__mode = "kv"})
|
||||||
|
|
||||||
--- (ToDo: docu)
|
-- Identity function for copcall
|
||||||
|
local function copcall_id(trace, ...)
|
||||||
|
return ...
|
||||||
|
end
|
||||||
|
|
||||||
|
--- This is a coroutine-safe drop-in replacement for Lua's "xpcall"-function
|
||||||
|
-- @param f Lua function to be called protected
|
||||||
|
-- @param err Custom error handler
|
||||||
|
-- @param ... parameters passed to the function
|
||||||
|
-- @return a boolean whether the function call succeeded and the return values of either the function or the error handler
|
||||||
function coxpcall(f, err, ...)
|
function coxpcall(f, err, ...)
|
||||||
local res, co = oldpcall(coroutine.create, f)
|
local res, co = oldpcall(coroutine.create, f)
|
||||||
if not res then
|
if not res then
|
||||||
|
@ -524,17 +542,15 @@ function coxpcall(f, err, ...)
|
||||||
return performResume(err, co, ...)
|
return performResume(err, co, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- (ToDo: docu)
|
--- This is a coroutine-safe drop-in replacement for Lua's "pcall"-function
|
||||||
|
-- @param f Lua function to be called protected
|
||||||
|
-- @param ... parameters passed to the function
|
||||||
|
-- @return a boolean whether the function call succeeded and the returns values of the function or the error object
|
||||||
function copcall(f, ...)
|
function copcall(f, ...)
|
||||||
return coxpcall(f, id, ...)
|
return coxpcall(f, copcall_id, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- (ToDo: docu)
|
-- Handle return value of protected call
|
||||||
local function id(trace, ...)
|
|
||||||
return ...
|
|
||||||
end
|
|
||||||
|
|
||||||
--- (ToDo: docu)
|
|
||||||
function handleReturnValue(err, co, status, ...)
|
function handleReturnValue(err, co, status, ...)
|
||||||
if not status then
|
if not status then
|
||||||
return false, err(debug.traceback(co, (...)), ...)
|
return false, err(debug.traceback(co, (...)), ...)
|
||||||
|
@ -546,7 +562,7 @@ function handleReturnValue(err, co, status, ...)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- (ToDo: docu)
|
-- Resume execution of protected function call
|
||||||
function performResume(err, co, ...)
|
function performResume(err, co, ...)
|
||||||
return handleReturnValue(err, co, coroutine.resume(co, ...))
|
return handleReturnValue(err, co, coroutine.resume(co, ...))
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue