blob: f4f9d4f30d442876d4a261c629473362f4280d2e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
--
-- This file is part of LEM, a Lua Event Machine.
-- Copyright 2011-2012 Emil Renner Berthing
--
-- LEM is free software: you can redistribute it and/or
-- modify it under the terms of the GNU General Public License as
-- published by the Free Software Foundation, either version 3 of
-- the License, or (at your option) any later version.
--
-- LEM is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with LEM. If not, see <http://www.gnu.org/licenses/>.
--
local M = require 'lem.streams.core'
do
local type = type
local parsers = M.parsers
local parser_available = parsers.available
parsers.available = nil
local parser_target = parsers.target
parsers.target = nil
function M.reader(readp)
return function(self, fmt, ...)
if fmt == nil then
return readp(self, parser_available)
end
if type(fmt) == 'number' then
return readp(self, parser_target, fmt)
end
local parser = parsers[fmt]
if parser == nil then
error('invalid format', 2)
end
return readp(self, parser, ...)
end
end
M.IStream.read = M.reader(M.IStream.readp)
end
return M
-- vim: ts=2 sw=2 noet:
|