diff options
Diffstat (limited to '')
-rw-r--r-- | LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/lzio_mk2.lua | 106 |
1 files changed, 0 insertions, 106 deletions
diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/lzio_mk2.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/lzio_mk2.lua deleted file mode 100644 index 6378366..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/lzio_mk2.lua +++ /dev/null | |||
@@ -1,106 +0,0 @@ | |||
1 | --[[-------------------------------------------------------------------- | ||
2 | |||
3 | lzio.lua | ||
4 | Lua 5 buffered streams in Lua | ||
5 | This file is part of Yueliang. | ||
6 | |||
7 | Copyright (c) 2005-2006 Kein-Hong Man <khman@users.sf.net> | ||
8 | The COPYRIGHT file describes the conditions | ||
9 | under which this software may be distributed. | ||
10 | |||
11 | See the ChangeLog for more information. | ||
12 | |||
13 | ----------------------------------------------------------------------]] | ||
14 | |||
15 | --[[-------------------------------------------------------------------- | ||
16 | -- Notes: | ||
17 | -- * | ||
18 | ----------------------------------------------------------------------]] | ||
19 | |||
20 | --[[-------------------------------------------------------------------- | ||
21 | -- local zio_init = require("lzio.lua") | ||
22 | -- local z = zio_init("@<filename>") | ||
23 | -- local z = zio_init("<string>") | ||
24 | -- z:getc() | ||
25 | -- * get next character from input stream | ||
26 | -- z:fill() | ||
27 | -- * fills an empty stream buffer | ||
28 | -- z.name | ||
29 | -- * name of the chunk, "@<filename>" or "=string" | ||
30 | ----------------------------------------------------------------------]] | ||
31 | |||
32 | --[[-------------------------------------------------------------------- | ||
33 | -- Format of z structure (ZIO) | ||
34 | -- z.n -- bytes still unread | ||
35 | -- z.p -- last read position in buffer | ||
36 | -- z.reader -- chunk reader function | ||
37 | -- z.data -- data buffer | ||
38 | -- z.name -- name of stream | ||
39 | ----------------------------------------------------------------------]] | ||
40 | |||
41 | return | ||
42 | function(buff) | ||
43 | --[[-------------------------------------------------------------------- | ||
44 | -- initialize reader | ||
45 | -- * reader should return a string, or nil if nothing else to parse | ||
46 | ----------------------------------------------------------------------]] | ||
47 | local reader | ||
48 | local z = {} | ||
49 | if string.sub(buff, 1, 1) == "@" then | ||
50 | ---------------------------------------------------------------- | ||
51 | -- create a chunk reader function from a source file | ||
52 | ---------------------------------------------------------------- | ||
53 | z.name = buff | ||
54 | local BUFFERSIZE = 512 | ||
55 | local h = io.open(string.sub(buff, 2), "r") | ||
56 | if not h then return nil end | ||
57 | reader = function() | ||
58 | if not h or io.type(h) == "closed file" then return nil end | ||
59 | local buff = h:read(BUFFERSIZE) | ||
60 | if not buff then h:close(); h = nil end | ||
61 | return buff | ||
62 | end | ||
63 | else | ||
64 | ---------------------------------------------------------------- | ||
65 | -- create a chunk reader function from a source string | ||
66 | ---------------------------------------------------------------- | ||
67 | z.name = "=string" | ||
68 | reader = function() | ||
69 | if not buff then return nil end | ||
70 | local data = buff | ||
71 | buff = nil | ||
72 | return data | ||
73 | end | ||
74 | end | ||
75 | --[[-------------------------------------------------------------------- | ||
76 | -- fills an empty stream buffer, returns first character | ||
77 | ----------------------------------------------------------------------]] | ||
78 | function z:fill() | ||
79 | local data = z.reader() | ||
80 | z.data = data | ||
81 | if not data or data == "" then return "EOZ" end | ||
82 | z.n, z.p = string.len(data) - 1, 1 | ||
83 | return string.sub(data, 1, 1) | ||
84 | end | ||
85 | --[[-------------------------------------------------------------------- | ||
86 | -- get next character, fills buffer if characters needed | ||
87 | ----------------------------------------------------------------------]] | ||
88 | function z:getc() | ||
89 | local n, p = z.n, z.p + 1 | ||
90 | if n > 0 then | ||
91 | z.n, z.p = n - 1, p | ||
92 | return string.sub(z.data, p, p) | ||
93 | else | ||
94 | return self:fill() | ||
95 | end | ||
96 | end | ||
97 | --[[-------------------------------------------------------------------- | ||
98 | -- initialize input stream object | ||
99 | ----------------------------------------------------------------------]] | ||
100 | if not reader then return end | ||
101 | z.reader = reader | ||
102 | z.data = "" | ||
103 | z.n, z.p = 0, 0 | ||
104 | return z | ||
105 | --[[------------------------------------------------------------------]] | ||
106 | end | ||