diff options
Diffstat (limited to '')
-rw-r--r-- | LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/lzio_mk4.lua | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/lzio_mk4.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/lzio_mk4.lua new file mode 100644 index 0000000..d97c795 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/lzio_mk4.lua | |||
@@ -0,0 +1,82 @@ | |||
1 | --[[-------------------------------------------------------------------- | ||
2 | |||
3 | lzio.lua | ||
4 | Lua 5 buffered streams in Lua | ||
5 | This file is part of Yueliang. | ||
6 | |||
7 | Copyright (c) 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 | -- * this is a line-based input streamer for the MK4 lexer | ||
18 | -- * all EOL (end-of-line) characters are translated to "\n" | ||
19 | -- * if last line in a file does not have an EOL character, this | ||
20 | -- streamer adds one, the ambiguity is due to "*l" stripping | ||
21 | -- * EOF uses an empty string to simplify testing in lexer | ||
22 | ----------------------------------------------------------------------]] | ||
23 | |||
24 | --[[-------------------------------------------------------------------- | ||
25 | -- local zio_init = require("lzio.lua") | ||
26 | -- local z = zio_init("@<filename>") | ||
27 | -- local z = zio_init("<string>") | ||
28 | -- z:getln() | ||
29 | -- * get next line from input stream | ||
30 | -- z.name | ||
31 | -- * name of the chunk, "@<filename>" or "=string" | ||
32 | ----------------------------------------------------------------------]] | ||
33 | |||
34 | --[[-------------------------------------------------------------------- | ||
35 | -- Format of z structure (ZIO) | ||
36 | -- z.getln -- chunk reader function, reads line-by-line | ||
37 | -- z.name -- name of stream | ||
38 | ----------------------------------------------------------------------]] | ||
39 | |||
40 | return | ||
41 | function(buff) | ||
42 | --[[-------------------------------------------------------------------- | ||
43 | -- initialize reader | ||
44 | -- * reader should return a string with an EOL character, or an empty | ||
45 | -- string if there is 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 h = io.open(string.sub(buff, 2), "r") | ||
55 | if not h then return nil end | ||
56 | reader = function() | ||
57 | if not h or io.type(h) == "closed file" then return nil end | ||
58 | local data = h:read("*l") | ||
59 | if not data then h:close(); return "" end | ||
60 | return data.."\n" | ||
61 | end | ||
62 | else | ||
63 | ---------------------------------------------------------------- | ||
64 | -- create a chunk reader function from a source string | ||
65 | ---------------------------------------------------------------- | ||
66 | z.name = "=string" | ||
67 | reader = function() | ||
68 | if not buff then return nil end | ||
69 | local p, q, data, eol = string.find(buff, "([^\r\n]*)(\r?\n?)") | ||
70 | buff = string.sub(buff, q + 1) | ||
71 | if data == "" and eol == "" then return "" end | ||
72 | return data..eol | ||
73 | end | ||
74 | end | ||
75 | --[[-------------------------------------------------------------------- | ||
76 | -- initialize input stream object | ||
77 | ----------------------------------------------------------------------]] | ||
78 | if not reader then return end | ||
79 | z.getln = reader | ||
80 | return z | ||
81 | --[[------------------------------------------------------------------]] | ||
82 | end | ||