mirror of
https://github.com/openwrt/luci.git
synced 2026-08-30 12:51:53 +04:00
Move inline documentation into separate files.
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
This commit is contained in:
@@ -25,14 +25,9 @@ local char = string.char
|
||||
|
||||
local getmetatable = getmetatable
|
||||
|
||||
--- LuCI JSON-Library
|
||||
-- @cstyle instance
|
||||
module "luci.json"
|
||||
|
||||
|
||||
--- Directly decode a JSON string
|
||||
-- @param json JSON-String
|
||||
-- @return Lua object
|
||||
function decode(json, ...)
|
||||
local a = ActiveDecoder(function() return nil end, ...)
|
||||
a.chunk = json
|
||||
@@ -41,9 +36,6 @@ function decode(json, ...)
|
||||
end
|
||||
|
||||
|
||||
--- Direcly encode a Lua object into a JSON string.
|
||||
-- @param obj Lua Object
|
||||
-- @return JSON string
|
||||
function encode(obj, ...)
|
||||
local out = {}
|
||||
local e = Encoder(obj, 1, ...):source()
|
||||
@@ -56,19 +48,10 @@ function encode(obj, ...)
|
||||
end
|
||||
|
||||
|
||||
--- Null replacement function
|
||||
-- @return null
|
||||
function null()
|
||||
return null
|
||||
end
|
||||
|
||||
--- Create a new JSON-Encoder.
|
||||
-- @class function
|
||||
-- @name Encoder
|
||||
-- @param data Lua-Object to be encoded.
|
||||
-- @param buffersize Blocksize of returned data source.
|
||||
-- @param fastescape Use non-standard escaping (don't escape control chars)
|
||||
-- @return JSON-Encoder
|
||||
Encoder = util.class()
|
||||
|
||||
function Encoder.__init__(self, data, buffersize, fastescape)
|
||||
@@ -80,8 +63,6 @@ function Encoder.__init__(self, data, buffersize, fastescape)
|
||||
getmetatable(self).__call = Encoder.source
|
||||
end
|
||||
|
||||
--- Create an LTN12 source providing the encoded JSON-Data.
|
||||
-- @return LTN12 source
|
||||
function Encoder.source(self)
|
||||
local source = coroutine.create(self.dispatch)
|
||||
return function()
|
||||
@@ -208,11 +189,6 @@ Encoder.parsers = {
|
||||
}
|
||||
|
||||
|
||||
--- Create a new JSON-Decoder.
|
||||
-- @class function
|
||||
-- @name Decoder
|
||||
-- @param customnull Use luci.json.null instead of nil for decoding null
|
||||
-- @return JSON-Decoder
|
||||
Decoder = util.class()
|
||||
|
||||
function Decoder.__init__(self, customnull)
|
||||
@@ -220,8 +196,6 @@ function Decoder.__init__(self, customnull)
|
||||
getmetatable(self).__call = Decoder.sink
|
||||
end
|
||||
|
||||
--- Create an LTN12 sink from the decoder object which accepts the JSON-Data.
|
||||
-- @return LTN12 sink
|
||||
function Decoder.sink(self)
|
||||
local sink = coroutine.create(self.dispatch)
|
||||
return function(...)
|
||||
@@ -230,8 +204,6 @@ function Decoder.sink(self)
|
||||
end
|
||||
|
||||
|
||||
--- Get the decoded data packets after the rawdata has been sent to the sink.
|
||||
-- @return Decoded data
|
||||
function Decoder.get(self)
|
||||
return self.data
|
||||
end
|
||||
@@ -526,11 +498,6 @@ Decoder.parsers = {
|
||||
}
|
||||
|
||||
|
||||
--- Create a new Active JSON-Decoder.
|
||||
-- @class function
|
||||
-- @name ActiveDecoder
|
||||
-- @param customnull Use luci.json.null instead of nil for decoding null
|
||||
-- @return Active JSON-Decoder
|
||||
ActiveDecoder = util.class(Decoder)
|
||||
|
||||
function ActiveDecoder.__init__(self, source, customnull)
|
||||
@@ -541,8 +508,6 @@ function ActiveDecoder.__init__(self, source, customnull)
|
||||
end
|
||||
|
||||
|
||||
--- Fetches one JSON-object from given source
|
||||
-- @return Decoded object
|
||||
function ActiveDecoder.get(self)
|
||||
local chunk, src_err, object
|
||||
if not self.chunk then
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
---[[
|
||||
LuCI JSON-Library
|
||||
|
||||
@cstyle instance
|
||||
module "luci.json"
|
||||
]]
|
||||
|
||||
---[[
|
||||
Directly decode a JSON string
|
||||
|
||||
@class function
|
||||
@name decode
|
||||
@param json JSON-String
|
||||
@return Lua object
|
||||
]]
|
||||
|
||||
---[[
|
||||
Direcly encode a Lua object into a JSON string.
|
||||
|
||||
@class function
|
||||
@name encode
|
||||
@param obj Lua Object
|
||||
@return JSON string
|
||||
]]
|
||||
|
||||
---[[
|
||||
Null replacement function
|
||||
|
||||
@class function
|
||||
@name null
|
||||
@return null
|
||||
]]
|
||||
|
||||
---[[
|
||||
Create a new JSON-Encoder.
|
||||
|
||||
@class function
|
||||
@name Encoder
|
||||
@param data Lua-Object to be encoded.
|
||||
@param buffersize Blocksize of returned data source.
|
||||
@param fastescape Use non-standard escaping (don't escape control chars)
|
||||
@return JSON-Encoder
|
||||
]]
|
||||
|
||||
---[[
|
||||
Create an LTN12 source providing the encoded JSON-Data.
|
||||
|
||||
@class function
|
||||
@name Encoder.source
|
||||
@return LTN12 source
|
||||
]]
|
||||
|
||||
---[[
|
||||
Create a new JSON-Decoder.
|
||||
|
||||
@class function
|
||||
@name Decoder
|
||||
@param customnull Use luci.json.null instead of nil for decoding null
|
||||
@return JSON-Decoder
|
||||
]]
|
||||
|
||||
---[[
|
||||
Create an LTN12 sink from the decoder object which accepts the JSON-Data.
|
||||
|
||||
@class function
|
||||
@name Decoder.sink
|
||||
@return LTN12 sink
|
||||
]]
|
||||
|
||||
---[[
|
||||
Get the decoded data packets after the rawdata has been sent to the sink.
|
||||
|
||||
@class function
|
||||
@name Decoder.get
|
||||
@return Decoded data
|
||||
]]
|
||||
|
||||
---[[
|
||||
Create a new Active JSON-Decoder.
|
||||
|
||||
@class function
|
||||
@name ActiveDecoder
|
||||
@param customnull Use luci.json.null instead of nil for decoding null
|
||||
@return Active JSON-Decoder
|
||||
]]
|
||||
|
||||
---[[
|
||||
Fetches one JSON-object from given source
|
||||
|
||||
@class function
|
||||
@name ActiveDecoder.get
|
||||
@return Decoded object
|
||||
]]
|
||||
|
||||
@@ -9,17 +9,10 @@ local nixio = require "nixio", require "nixio.util"
|
||||
local tostring, assert, setmetatable = tostring, assert, setmetatable
|
||||
local error = error
|
||||
|
||||
--- LuCI RPC Client.
|
||||
-- @cstyle instance
|
||||
module "luci.rpcc"
|
||||
|
||||
RQLIMIT = 32 * nixio.const.buffersize
|
||||
|
||||
--- Create a new JSON-RPC stream client.
|
||||
-- @class function
|
||||
-- @param fd File descriptor
|
||||
-- @param v1 Use protocol version 1.0
|
||||
-- @return RPC Client
|
||||
Client = util.class()
|
||||
|
||||
function Client.__init__(self, fd, v1)
|
||||
@@ -29,11 +22,6 @@ function Client.__init__(self, fd, v1)
|
||||
self.v1 = v1
|
||||
end
|
||||
|
||||
--- Request an RP call and get the response.
|
||||
-- @param method Remote method
|
||||
-- @param params Parameters
|
||||
-- @param notification Notification only?
|
||||
-- @return response
|
||||
function Client.request(self, method, params, notification)
|
||||
local oldchunk = self.decoder and self.decoder.chunk
|
||||
self.decoder = json.ActiveDecoder(self.fd:blocksource(nil, RQLIMIT))
|
||||
@@ -58,9 +46,6 @@ function Client.request(self, method, params, notification)
|
||||
end
|
||||
end
|
||||
|
||||
--- Create a transparent RPC proxy.
|
||||
-- @param prefix Method prefix
|
||||
-- @return RPC Proxy object
|
||||
function Client.proxy(self, prefix)
|
||||
prefix = prefix or ""
|
||||
return setmetatable({}, {
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
---[[
|
||||
LuCI RPC Client.
|
||||
|
||||
@cstyle instance
|
||||
module "luci.rpcc"
|
||||
]]
|
||||
|
||||
---[[
|
||||
Create a new JSON-RPC stream client.
|
||||
|
||||
@class function
|
||||
@param fd File descriptor
|
||||
@param v1 Use protocol version 1.0
|
||||
@return RPC Client
|
||||
]]
|
||||
|
||||
---[[
|
||||
Request an RP call and get the response.
|
||||
|
||||
@class function
|
||||
@name Client.request
|
||||
@param method Remote method
|
||||
@param params Parameters
|
||||
@param notification Notification only?
|
||||
@return response
|
||||
]]
|
||||
|
||||
---[[
|
||||
Create a transparent RPC proxy.
|
||||
|
||||
@class function
|
||||
@name Client.proxy
|
||||
@param prefix Method prefix
|
||||
@return RPC Proxy object
|
||||
]]
|
||||
|
||||
@@ -5,16 +5,11 @@ local util = require "luci.util"
|
||||
local rawget, setmetatable = rawget, setmetatable
|
||||
local ipairs = ipairs
|
||||
|
||||
--- Transparent UCI over RPC client.
|
||||
-- @cstyle instance
|
||||
module "luci.rpcc.ruci"
|
||||
|
||||
|
||||
local Proxy = util.class()
|
||||
|
||||
--- Create a new UCI over RPC proxy.
|
||||
-- @param rpccl RPC client
|
||||
-- @return Network transparent UCI module
|
||||
function factory(rpccl)
|
||||
return {
|
||||
cursor = function(...)
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
---[[
|
||||
Transparent UCI over RPC client.
|
||||
|
||||
@cstyle instance
|
||||
module "luci.rpcc.ruci"
|
||||
]]
|
||||
|
||||
---[[
|
||||
Create a new UCI over RPC proxy.
|
||||
|
||||
@class function
|
||||
@name factory
|
||||
@param rpccl RPC client
|
||||
@return Network transparent UCI module
|
||||
]]
|
||||
|
||||
Reference in New Issue
Block a user